posted 16 years ago
John,
As always, the answer is...it depends. What do you need the class to do?
It's generally safe to include in your base class attributes that are likely to be common to any subclasses. In your example, it's true that many people are not parents, but it's fairly standard that a person can be a parent. In uses of the class where it matters, you simply check if the person has any children or not and go from there.
You want to be careful not to make your class differentiation too limiting in its distinctiveness. For example, if you create a base Person, and subclasses Parent and Driver...can a Parent ever be a Driver?
Always go back to your problem domain and figure out what level best captures what you're trying to do. And there's not always fast and hard answers, which is why sometimes OOAD sometimes feels more like an art than a science.
As an aside, in your sample class, you'll probably want to use a Collections class rather than an array for your children. You get a lot more flexibility out of the right Collection.
There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James