multiple subclass problem

this is the code that i write (the real is not much different but is too dependent to other code)
making exercize with subclass



class Point:
    def update(self):
        pass


class PointStatic(Point):
    def __init__(self, position=[0,0,0]):
        self.position = Vector(position)



class PointDynamic(PointStatic):
    def __init__(self, position=[0,0,0], velocity=[0,0,0]):
        super().__init__(position)
        self.Velocity = Vector(velocity)

    def update(self):
        self.update_physic()

    def update_physic(self)
        self.velocity += GRAVITY
        self.position += self.velocity




class ShapeStatic(PointStatic):
    def __init__(self, position=[0,0,0], lines):
        super().__init__(position)
        self.lines = lines

    def update(self):
        self.draw_lines()

    def drawlines(self):
        print(self.lines)


class ShapeDynamic(????):
    def __init__(self, position=[0,0,0], velocity=[0,0,0], lines):
        super().__init__(????)


as you see each class add some piece of code and it work well until a ShapeStatic

question:
ShapeDynamic should be already done , basically -> ShapeDynamic = ShapeStatic + PointDynamic

but if i subclass from ShapeStatic i cannot subclass from PointDynamic
how make?

I suggest you take a sheet of paper and draw the inheritance tree of the classes you have above. Then add the inheritance relation what you want to add. Then you should be able to see why it is not possible.

The answer is in this statements

i see that a certain point the classes follow 2 different ways,
anyway not there conflicts ,so should be sufficient “joint” 2 class…

or i wrong to make the structure?

ShapeStatic is a PointDynamic already. It makes no sense to subclass a class that it already is.

According to the naming, you should question if the inheritance tree is really what you want. Because it seems you want to model different aspects:

physics type: static, dynamic
form: point, shape

If you want to be able to model any combination try this structure:


(Physical) --> Static --> Dynamic

(Form)--> Point --> Shape

These two class types are independent from each other.

You can combine them in a specific class, to get both aspects:

DynamicShape(Dynamic, Shape)
StaticPoint(Static, Point)

You will be able to check if a class has the aspects, before you rely on them:


isinstance(specificObject, Physics)
isinstance(specificObject, Form)

Technically, Python (and others like C++ etc.) support multiple inheritance but it’s generally not a common practice due to the complications that it can introduce.

Another topic you could look into, specific to object-oriented programming and your question, is inheritance vs composition:
http://learnpythonthehardway.org/book/ex44.html