Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
If I create an object with certain properties, then use this to create another object (by passing it to a constructor) which will be initialised with those properties, this would seem to be a Prototype, but this is a little different from the GoF pattern - any thoughts? ---
Looks like a
to me. ---
You would lose the advantage of polymorphism that the GoF formulation of the Prototype pattern gives you. --
Exactly... Prototyping is all about creating a replica of myself. I don't know my exact type, i.e. polymorphism. But I can duplicate myself when somebody else needs a duplicate of me, and he doesn't care about my type (position in the inheritance tree). --Praveen
Could it be that the
could be included under this title?
The use case I think think of while using this pattern is to make certain properties of an object immutable while creating new object. The immutable properties can be changed only in prototype. Thus making the object created effectively immutable. --- ShripadAgashe
of this page (last edited
September 25, 2011
with title or text search