how to organize classes in ruby if they are literal subclasses
Posted
by RetroNoodle
on Stack Overflow
See other posts from Stack Overflow
or by RetroNoodle
Published on 2010-06-16T20:24:22Z
Indexed on
2010/06/16
23:42 UTC
Read the original article
Hit count: 155
I know that title didn't make sense, Im sorry! Its hard to word what I am trying to ask. I had trouble googling it for the same reason.
So this isn't even Ruby specific, but I am working in ruby and I am new to it, so bear with me.
So you have a class that is a document. Inside each document, you have sentences, and each sentence has words. Words will have properties, like "noun" or a count of how many times they are used in the document, etc.
I would like each of the elements, document, sentence, word be an object.
Now, if you think literally - sentences are in documents, and words are in sentences.
Should this be organized literally like this as well? Like inside the document class you will define and instantiate the sentence objects, and inside the sentence class you will define and instantiate the words?
Or, should everything be separate and reference each other? Like the word class would sit outside the sentence class but the sentence class would be able to instantiate and work with words?
This is a basic OOP question I guess, and I suppose you could argue to do it either way. What do you guys think?
Each sentence in the document could be stored in a hash of sentence objects inside the document object, and each word in the sentence could be stored in a hash of word objects inside the sentence.
I dont want to code myself into a corner here, thats why I am asking, plus I have wondered this before in other situations.
Thank you!
© Stack Overflow or respective owner