[Tutor] Design Question... from a newbie

Alan Gauld alan.gauld at freenet.co.uk
Thu Oct 21 09:53:35 CEST 2004


> > like health points etc, just the stuff that is unique to a dwarf).
Each
> > level in the class heirachy will introduce it's own relevent
attributes.
> > Then, when someone decides to be a dwarf, a lot of the attributes
will
> > be automatically set just because they're using the dwarf class.

> This sounds like "interfaces".

Nope, interfaces are a specific type of abstract base class with
the added distinction that they have no implementation of the
methods they declare as well as no data members.

A base class:

class Shape:
    Location = (0,0)
    Color = BLACK
    def move(self, x,y):
       self.lOcation = (x,y)


compared to an interface:

class iShape:
    def move(self, x,y): pass

Base classes are useful things in their own right, interfaces are
IMHO only useful as a form of loosening static typing in languages
like Java which don't support multiple inheritance.

Alan G.



More information about the Tutor mailing list