mardi 25 août 2020

python design pattern for hierarchical oop

i created following hierarcy for my project.

Abstract Car class which has common methods and common fields for all cars. Then i inherited model classes like BMW,Audi,Mercedes,Pegout,Ford and etc. which has only its own fields and methods.

class hierarchy for my project

lets assume i have similar hierarchy with classes for some other topics and i packaged each topic like :

\project folder  
    \Cars  
        BMW.py  
        Audi.py  
        ...
    \topic2  
        ...
    \topic3  
        ...
    \...  
    \my_project.py

in my_project.py i want to add all concrete classes and use them.But my problem is here that there are too many classes and i dont know how should i keep them.
Should i keep them as objects(composition) in a container such as list like myObjects = [Audi(),BMW(),...]
or should i go multiple inheritance to keep all classes in one like class Vehicle(BMW,Audi,...) (for that case i also dont know how to handle with common methods. i mean what happens if i call a common method from Car class ?)
or is there any better solution?

Aucun commentaire:

Enregistrer un commentaire