jeudi 6 juillet 2017

Modeling multiple - and very different and not related - class dependencies

I'm using Python 2.7.

I have to create a class called NiceTrip.

But NiceTrip is made of several non-related classes: Food, Tools and Car.

All those three classes have some dependency injections in there.

Class Food:

    def __init__(self, supermarket=None):
        self.supermarket = supermarket

    def is_healthy(self):
        pass

    def healthy_foods(self):
        pass

    def allowed_foods(self):
        pass


Class Car:

    def __init__(self, renter=None):
        self.renter = renter

    def has_gas(self):
        pass

    def tools(self):
        pass

    def has_food_pockets(self):
        pass


Class Tool:

    def __init__(self, dads_house=None):
        self.dads_house = dads_house

    def is_usefull(self):
        pass

    def can_lift_car(self):
        pass

    def can_turn_screws(self):
        pass

    def can_glow(self):
        pass

So... how should I model my NiceTrip in a way my NiceTrip have a minimal dependency, without knowing about how to build the other classes, without knowing about the other classes methods, without using messy Python interfaces workarounds and without exploding my system with lots of "loaders"?

Of course I'm using a simple example, in my actual problem my classes are part of a more complex system.

Is more like having a class Juice that uses Tools, Food, WeatherConditions and CurrencyRates, and all those classes with lots of "dependencies".

And NiceTrip itself would be part of a group even bigger, like NiceTrip being part of Health that uses NiceTrip, Friends, Education and Spirituality.

Sorry if it's a simple question... but all the modeling examples that I found was about different but very meaning related classes (Products, Customers and Shipping for example, or Animal, Dog and Duck) and more badly, examples are typically a single layer system.

Thanks for any enlightenment!

Aucun commentaire:

Enregistrer un commentaire