help needed with classes/inheritance

barbaros barbaros at ptmat.fc.ul.pt
Wed Apr 23 04:54:13 EDT 2008


Hello everybody,

I am building a code for surface meshes (triangulations for instance).
I need to implement Body objects (bodies can be points, segments,
triangles and so on), then a Mesh will be a collection of bodies,
together with their neighbourhood relations.
I also need OrientedBody objects, which consist in a body
together with a plus or minus sign to describe its orientation.
So, basically an OrientedBody is just a Body with an
integer label stuck on it.

I implemented it in a very crude manner:
------------------------------------------
class Body:
  [...]
class OrientedBody:
  def __init__ (self,b,orient=1):
    # b is an already existing body
    assert isinstance(b,Body)
    self.base = b
    self.orientation = orient
-------------------------------------------

My question is: can it be done using inheritance ?
I recall that I need three distinct objects:
the basic (non-oriented) body, the same body with positive
orientation and the same body with negative orientation.

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



More information about the Python-list mailing list