[Tutor] classes and inheritance

alan.gauld@bt.com alan.gauld@bt.com
Sun, 29 Sep 2002 23:39:06 +0100


PMFJI

America was great, but I'm back and got this was my first 
tutor email after resuming the feed...

> class User:
>     data:
>         name (used for saving and file name)
>         passwrd
>     actions:
>         get name
>         get passwrd

Recall responsibility driven design is the key to good OO.

What are the responsibilities of the objects, not the data 
they contain?

Now maybe a User object has the responsibility to manage 
user names/passwords but what else does it DO?
Those are the methods you need to focus on, then just add 
the necessary data to support that.

Thus you need change password as a method probably.
But maybe also you need to monitor status of users 
- alive/dead/numer of lives etc depending on the rules 
of the game...

I could be way off line here, but every time I see 
a class where the only methods are get/set methods of 
the data I get nervous. Its nearly always the wrong design.

As regards the subclasses you don't need to repeat the 
data/operations since they are already specified when 
you say you inherit from User...

Finally I concur with the bottom comment about instantiating 
abstract classes. You might use the subclasses *as if* they 
were higher level abstracts but you would likely never 
instantiate an abstract directly.

Alan G.