mercredi 20 janvier 2016

Is there a design pattern for creating a prototype with only some values differing?

Class heirarchy
The client uses them via the base class (java code) :

BaseClass baseObj1 = new DerivedClass("valueofreqdfeature");
Map<String, Object> features = Collections.singletonMap("requiredFeature1Name","requiredFeatureValue");
BaseClass newBaseObj = baseObj1.createNewConcreteFeature(features);

createNewConcreteFeature would get only the requiredFeature values from the map and return an instance. This seems like a method that would be static in the derived class but then the client can't create derived class instances with an existing object. Is there a more elegant way of writing this? or does this have some applicable pattern?

Aucun commentaire:

Enregistrer un commentaire