styfle
styfle

Reputation: 24720

What is the best way to convert relational to object oriented?

Since I learned about RDBMS, I started thinking in the relational model and less in the object oriented. Now I'm having trouble trying to store and query data in Java data structures.

I want to write an application that has entity sets that relate to each other so I made each entity its own class. The attributes for each entity are the instance variables. Okay I think we're good so far. Title and Game are all entities. Game ISA Title so Title should be the parent class and Game should inherit from Title (think of Game as the physical copy and Title as the name of the Game).

I have a set of games in my main class and I can iterate through if I want to find a specific Game. How would I find a specific Title? I don't have a set of titles because Title is inherited so I would assume I should just iterate through games and when I find a name of a title, add it to a set so that I only get unique titles back.

Game is mutable (isBought can change) so is using a Set a bad idea? What is the best way to create Entity sets in Java? Using a Map instead of a set to map an id to an object?

Upvotes: 1

Views: 1536

Answers (2)

nvogel
nvogel

Reputation: 25534

There is no fundamental gap between relational and OO models. The relational data model is a type system that supports relation types and relational operators (and other types as well). An OO data model is a type system that supports inheritence.

The mistake that people often make when considering these paradigms is to equate types (classes) in OO terms with relations or tuples in the relational model. Date and Darwen call this the First Great Blunder. The reality is much simpler than that. Types are types, in both the relational model and the OO model. The two paradigms are orthogonal and complementary to each other, they are not mutually exclusive.

What the much-hyped OO/RM mismatch really means is that a programmer wishes to implement certain patterns of transformations which his software tools don't easily support. The relational model is not to blame. The software makers are.

Upvotes: 2

Bozho
Bozho

Reputation: 597422

Fixing the object-relational gap is not an easy task. There are ORM (object-relational mapping) frameworks that do that. But they have some learning curve. Hibernate and EclipseLink are two implementations of the ORM standard in Java - JPA (java persistance API).

Upvotes: 5

Related Questions