help needed with classes/inheritance

barbaros barbaros at ptmat.fc.ul.pt
Wed Apr 23 11:44:50 EDT 2008


On Apr 23, 10:48 am, Bruno Desthuilliers <bruno.
42.desthuilli... at websiteburo.invalid> wrote:

>
> > My question is: can it be done using inheritance ?
>
> Technically, yes:
>
> class OrientedBody(Body):
>    def __init__(self, orient=1):
>      Body.__init__(self)
>      self.orient = 1
>
> Now if it's the right thing to do is another question...

If I understand correctly, in the above implementation I cannot
define firstly a (non-oriented) body, and then build, on top of it,
two bodies with opposite orientations. The point is, I want
both oriented bodies to share the same base Body object.

> Another
> possible design could be to have an orient attribute on the Body class
> itself, with 0 => non-oriented (default), 1 => 'plus', -1 => 'minus' (or
> any other convention, depending on how you use this attribute).

The above comments apply here, too.

In what concerns other suggestion, about Python language,
I shall do my best to understand them and apply them.

Thank you. Cristian Barbarosie
http://cmaf.fc.ul.pt/~barbaros



More information about the Python-list mailing list