Results 1 to 5 of 5
Thread: OOP design and Databases.
- 10-06-2009, 08:07 AM #1
Member
- Join Date
- Oct 2009
- Location
- Flanders
- Posts
- 3
- Rep Power
- 0
OOP design and Databases.
Hi, my first post here.
I would like to make a program that's able to extract words from sentences and determine them grammatically.
Therefore, I made a hierarchy: a base class "Word" from which classes as "Verb", "Substantive", ... are derived (and so for all the categories of words). This seems logical to me because a substantive IS a word. I want to put these words in a database (MySQL). This database has one main table which contains all occurrences of all words. In addition to this, there are tables for each category: a table "Verbs", a table "Substantives",...
Now, the logics for retrieving words from the database or to add a new word to the database, should be handled by the objects (words in this case) themselves. According to Ivor Horton ('Beginning Java 2') this is the right object-oriented way to do things.
My question is: do I put the database handling logic in the parent class (Word) or in the derived classes ("Verb", "Article",...)? Each approach has his advantages: if the program processes a sentence and encounters a new word, it has no idea of the category.
On the other hand, when the program adds a new word to the table, it should be aware of the category, in order to put the word in the right table.
I'm in doubt which approach is the best? Or can you put a part of the database-transfer-logic in the parent class and a part in the derived class?
But this seems somewhat "artificial" or "unnatural" to me. I've been asking myself if there are maybe situations where OOP isn't appropriate? (On the other hand, grammatical structures lend themselves very well too OOP)
I've put it in "New to Java", because I'm quite new to Java. Thank you for your thoughts.
- 10-06-2009, 09:13 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Don't put any database logic in the Words at all. Words have nothing to do with databases. Let them be reusable classes that model the grammatical structures you are dealing with. Create separate DB access classes that do the DB work.
- 10-06-2009, 09:36 AM #3
Member
- Join Date
- Oct 2009
- Location
- Flanders
- Posts
- 3
- Rep Power
- 0
Thank you for your answer, r035198x, but Ivor Horton writes (in "Beginning Java 2") that this approach "does leave quite a lot to be desired". He says that the other approach is better because the class itself is responsible for ensuring that the correct mapping is performed between the object and the database.
Don't get me wrong, I am the the beginner, I am not trying to teach you. And intuitively I would prefer your approach, because it feels more natural (i.e. closer to reality).
But there seem to exit different opinions on how to implement OOP.
- 10-06-2009, 09:46 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 10-06-2009, 09:52 AM #5
Member
- Join Date
- Oct 2009
- Location
- Flanders
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
struts 2 and databases
By rantravee in forum Web FrameworksReplies: 1Last Post: 12-23-2008, 06:59 AM -
how to use XML databases
By paty in forum XMLReplies: 3Last Post: 08-16-2008, 12:11 AM -
Hibernate with multiple databases
By dsr0781 in forum JDBCReplies: 5Last Post: 06-23-2008, 01:06 PM -
Recommendation about databases
By tommy in forum JDBCReplies: 2Last Post: 07-28-2007, 05:04 AM -
multiple databases
By varunthecool in forum JDBCReplies: 2Last Post: 07-09-2007, 08:06 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks