[Tutor] classes and inheritance

CameronStoner wolf_binary@hotmail.com
Sun, 29 Sep 2002 09:10:20 -0700


    I do have a concrete program I am making.  It's a game.  I don't know if
you know anything about Japanese Anime, but it has some gundam things in it.
(gundams are big robots piloted by people)  I was thinking of making a
series of inheritance that would then result in a final subclass called
player that would have all the components necessary to describe that player
without having to make new objects out of the classes.  I was going to make
one object and then have a whole bunch of actions that could be placed upon
the player.  I still ,however, need to be able to make computer controled
opponents that are of the gundam class.
See example:

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

class gundam inherits from User:
    data:
        gundam name
        gundam health
    actions:
        get gundam name
        get gundam health

class player inherits from gundam:
    data:
        character's name
        character's health
    actions:
        get character's name
        get character's health

    OOP seemed to be the only way to feezably handle what was going on in an
easier way than the usual functional programming.

Thank,
Cameron Stoner



>Say I have a class Animal , Mamal, and Human.  Then go on to say
>that  Mamal inherits from Animal and that Human does from Mamal.  Can you
>make an object from Mamal that then is a generic Mamal that doesn't have
>the attributes of Human and is this a good programming practice?

Well... Yes and no...

It's really pointless to dicuss classes without knowing what
kind of problem you are trying to solve. Classes are not written
to model the world, but to serve some kind of function.

I think you will be better of if you think of a concrete program,
and the classes evolve because they are needed in the
program, not being written as an empty exercise.