Object-oriented programming and database management

MohsinG picture MohsinG · Jan 24, 2013 · Viewed 7k times · Source

I have been puzzled by this for a while now. My question is, how does object-oriented programming and database management work together? I can't seem to find much on how the two work together. I wanted to make a database driven application and I currently have a good book on object oriented programming that has a process for creating applications using object-oriented methodologies but I just get confused when we start involving databases.

Is a class diagram essentially a database design? Can we still query the database with SQL just like we do with relational databases? How is the data file stored and in what format? Are classes the equivalent to tables and their attributes equivalent to columns?

Thanks in advance I appreciate any responses and I did try google and the similar questions offered.

Answer

Joe Ratzer picture Joe Ratzer · Jan 24, 2013

It seems like you're coming up against the Object Relational Impedence Mismatch.

Is a class diagram essentially a database design?

No it isn't, the database model and your OO model may well be very different.

Can we still query the database with SQL just like we do with relational databases?

Yes you can, but you'll change the data into objects, see the Repository Pattern on how to do that.

How is the data file stored and in what format?

The same way and format RDBSs have been storing data for decades, I won't muddy the water by suggesting you look at the growing popularity of NoSQL systems.

Are classes the equivalent to tables and their attributes equivalent to columns?

Not necessarily, you'll be mapping the data in tables to objects in an OO design. Sometimes they might map almost directly. You might also, for example, have the data in 3 tables mapped to one object.