[Tutor] classes and inheritance

CameronStoner wolf_binary@hotmail.com
Mon, 30 Sep 2002 08:14:13 -0700


I'm glad you had a good time.

So your saying that I should just leave them as seperate classes?
    Oh, and I didn't list all the actions.  I'm in the design phase now and
I am just brainstorming how to do this.  Your not off base either on what
you were seeing in my design, I knew something was wrong and didn't know
what.  I was concentrating on the data and not on the methods.  This would
make for easier reusablility and make more sense.  I kept thinking why are
these inheriting from each other and only found that encapsulating them into
one class was the only reason.


> > 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.
>