Timeline for What are abstract classes and abstract methods?
Current License: CC BY-SA 3.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 11, 2012 at 16:50 | comment | added | FrustratedWithFormsDesigner |
I think Infant , Child , Adult , are better as states, because a human that is an infant will then become a human that is child, then an adult, but it is the same object that is changing state by aging. Man and Woman I think are also better as parts of a state because sometimes a Human that is-a Man could undergo a procedure to become a Woman (and vice-versa) - it's not common but it does happen ;) A model that makes Man and Woman as separate classes is much less flexible, but might be OK depending on what system you're trying to model.
|
|
Dec 11, 2012 at 16:46 | comment | added | Maxood | I do agree with you partially. We can use overloaded constructors (POLYMORPHISM) for Infant, Child, Adult instead of deriving child classes(INHERITANCE). But what makes you say about Man and Woman to be represented as enumerated fields. Why? They are perfect for to be inherited classes. The example i just gave is for the novice learner. Thanks for your feedback. | |
Dec 11, 2012 at 16:45 | comment | added | FrustratedWithFormsDesigner |
If you really want to stick with this example though, you might want to make Hominid your abstract class, maybe with Human and Gorilla as two possible subclasses of it (though I'm not a taxonomist, so maybe this isn't the best way to do it?).
|
|
Dec 11, 2012 at 16:38 | comment | added | FrustratedWithFormsDesigner |
I don't know, I think Infant , Child , Adult would be better as different states of a Human object, and Man and Woman would be possible values for an enumerated field.
|
|
Dec 11, 2012 at 16:37 | history | answered | Maxood | CC BY-SA 3.0 |