another question about classes and subclassing

Alex Hall mehgcap at gmail.com
Tue May 18 17:51:33 EDT 2010


Hi again all,
More about classes. I am still looking into my battleship game, and I
will have several different craft. All craft have common attribs
(position, alive, and so on) but each craft may be a surface ship,
submarine, or airplane. All three are craft, but a submarine can be
submerged or not, which does not apply to a surface ship or a plane,
while a plane can be airborne or not, which is not applicable to the
other two. Is there any advantage to creating a craft class:

class craft():
 #has attribs common to any and all craft
#end class

then doing something like:

class submarine(craft):
 #sub-specific attribs
#end class

How would I create a submarine, and then get at the craft-level
attribs? Come to think of it, how would I pass anything to the craft
constructor (position and alive, for example) when creating a new
submarine object? Am I even doing this right to make submarine a
subclass of craft? Thanks.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap



More information about the Python-list mailing list