F
Fred Exley
I have a traditional application using a database and procedural code that
works fine. I'm re-writing it using the OOP methodology, just to see how
this may be the better way to do things. I think I've got a pretty good
grasp of the three pillars of OOP, and have objects properly defined using
inheritance, encapsulation, etc. as appropriate. Now it's time to do some
processing using real data, and the data resides on a relational database.
As best I can gather, the preferred OO way to do this in general is to:
Write a utility routine to load the data from the database into their
respective objects.
For tables in the database with a master/detail relationship (i.e., Order,
Order Items tables), represent this in OOP by creating another class, an
intersect object, that relates one Order with one Order Item instance.
Create yet another class, to be used as a container for these intersect
object items, using an ArrayList (to make use of that objects built-in
methods; insert, update, enumerate, etc.).
At this point, the actual data processing can begin. Create procedures that
solely operate on the objects we created, making use of the built-in methods
these objects provide, and writing our own methods as necessary.
When all the procedures are complete for whatever we're trying to do, use
another utility routine to write the resulting data transformations back to
the relational database we started with.
Is this about right? If so, doing it this way, what real-world advantages
do we now have using the OO methodology? Is all this added overhead really
worth it? The best scenario I can imagine is that maybe, once we've set
everything up in an OO model, the procedures that actually process that data
will be a fraction of the amount of procedural code required to simply
process against the database directly. In other words, is OOP really the
better way to go in real-world, production business applications, or is it
mainly a nice academic exercise? thanks
-Fred
works fine. I'm re-writing it using the OOP methodology, just to see how
this may be the better way to do things. I think I've got a pretty good
grasp of the three pillars of OOP, and have objects properly defined using
inheritance, encapsulation, etc. as appropriate. Now it's time to do some
processing using real data, and the data resides on a relational database.
As best I can gather, the preferred OO way to do this in general is to:
Write a utility routine to load the data from the database into their
respective objects.
For tables in the database with a master/detail relationship (i.e., Order,
Order Items tables), represent this in OOP by creating another class, an
intersect object, that relates one Order with one Order Item instance.
Create yet another class, to be used as a container for these intersect
object items, using an ArrayList (to make use of that objects built-in
methods; insert, update, enumerate, etc.).
At this point, the actual data processing can begin. Create procedures that
solely operate on the objects we created, making use of the built-in methods
these objects provide, and writing our own methods as necessary.
When all the procedures are complete for whatever we're trying to do, use
another utility routine to write the resulting data transformations back to
the relational database we started with.
Is this about right? If so, doing it this way, what real-world advantages
do we now have using the OO methodology? Is all this added overhead really
worth it? The best scenario I can imagine is that maybe, once we've set
everything up in an OO model, the procedures that actually process that data
will be a fraction of the amount of procedural code required to simply
process against the database directly. In other words, is OOP really the
better way to go in real-world, production business applications, or is it
mainly a nice academic exercise? thanks
-Fred