mercredi 14 juin 2017

Need a design pattern for getting only specific features common across classes

I have to choose a design pattern for the following scenario. Though I will be implementing it in Typescript, but I need to make it generic in order to implement it across languages.

Problem statement is that - Let's say I have functionalities driveInAir(), driveOnRoad(), driveOnWater() and some more.

Now I have classes which contains only subset or all of these features. For example - a flying car might have driveOnRoad and driveInAir, while a ship might have just driveOnWater. However the definition of each of these functionalities are common across classes and hence I do not want to redefine them.

Also a Ship should not be able to access driveOnRoad functionality. I am developing this in Typescript, but the design pattern chosen should be also extendable in other languages such as python, Java etc.

One of the ideal candidate for this is mixins which is another form of multiple inheritance where I define a class containing just one function defining a functionality. And class Ship or FlyingCar extends the classes which it needs. But mixins/multiple inheritance are not supported across the languages, so it's not something I am a big fan of. Any other suggestions?

Aucun commentaire:

Enregistrer un commentaire