Design Patterns - Creational

1. Prototype

  • Role: The Prototype pattern creates new objects by cloning one of a few stored prototypes. The Prototype pattern has two qualities: it speeds up the instantiation of very large, dynamically loaded classes, and it keeps a record of identifiable parts of a large data structure that can be copied without knowing the subclass from which they were created.
  • Implementation: In general, when an object is cloned, the new object is either a shallow or deep copy. A shallow copy duplicates all of the object's properties. If any property contains a reference type, the reference is copied. For the C# sample of prototype cloning we use MemberwiseClone for the creation of the shallow copy and Serialization for the deep copy (see Prototype<T> class definition). See the full example by downloading the source code.

Last edited Mar 14, 2010 at 7:26 PM by abilauca, version 4


No comments yet.