SE450: Clone: Prototype Pattern [8/32] |
For mutable objects, one might consider implementing a factory by cloning prototype objects, rather than calling a constructor each time.
Here is a static factory using constructors: dir:factory/person [source]
Here it is refactored to use prototypes: dir:clone/prototype [source]
In most cases, the constructor version is preferable in Java.