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.