samedi 15 août 2020

Design pattern for object assuming new features on the fly?

Suppose I have a class House.

I want to be adding specifications to my house, like a Garage, a SwimmingPool or a Garden, each coming with its own set of new methods.

If I used inheritance, I would have subclasses HouseWithGarage, HouseWithSwimmingPool and HouseWithGarden. But what if I wanted to have an object with a garage and a garden at the same time? What if later I wanted to add a swimmingpool to that same object at runtime?

Obviously inheritance doesn't work well here. Are you aware of any design pattern appropriate for this kind of problem?

Aucun commentaire:

Enregistrer un commentaire