mardi 10 janvier 2017

Adding functionality to the object (class) at runtime according to need

I have a requirement where i have to create a json file which will have children objects which can be description of vehicles

Like

Root
|- V1
|- V2

Now there can be any number of vehicle and only 1 root. Also these vehicle can be added as we need them for different requirements. New vehicle can also be added in near future.

So i thought of interface IV and all V1, V2, ... inherited from it. IV will have function getDescription which will be return by all concrete implementations and added to json file. So i can pass the array of V1, V2 to the constructor of Root and call execute to generate the json

Which design pattern is suggested for this kind of requirement. I thought of decorator pattern but in this case the root element will be different from the child elements, hence they may be inherited from different inrefaces

Aucun commentaire:

Enregistrer un commentaire