1. Single-piece mode
- intent
ensure that a class has only one instance and provides a global access to it.
- Implementation Points
the Singleton mode restricts the creation of classes rather than improving the creation of classes.
the instance constructor in the Singleton class can be set to protected to allow subclass derivation.
the Singleton mode generally does not support the icloneable interface, this may cause multiple object instances, which are in conflict with the original intention of the Singleton mode.
the Singleton mode generally does not support serialization, which may also lead to multiple object instances, this is also contrary to the original intention of the Singleton mode.
Singleton only manages object creation and does not manage object destruction, in terms of the overhead of platforms and objects that support garbage collection, we generally do not need to perform special management on their destruction.
the core of the Singleton mode is "How to control the use of new any call to the constructor of a class ".
- For details, see
http://terrylee.cnblogs.com/archive/2005/12/09/293509.html
2. Simple factory Model
- Intention
Provides a class for creating instances of a specific class according to certain conditions.
- Implementation points
The factory class creates fewer objects.
The customer only knows the parameters of the factory class passed in, and does not care about how to create the object (logic.
- For details, see
Http://www.cnblogs.com/anlyren/archive/2008/01/25/simple_Factory_Pattern.html
3. Factory method mode
- Intention
Defines an interface used to create objects, so that the subclass determines which class to instantiate. The factory method delays the instantiation of a class to its subclass.
- Summary
Factory methodThe solution is to solve the problem of the object creation time. It provides an extension policy that fits the principle of open and closed.
- For details, see
Http://terrylee.cnblogs.com/archive/2006/01/04/310716.html
4. Abstract Factory Model
- Intention
Provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes.
- Implementation points
The abstract factory delays the creation of product objects to subclass of its specific factory.
If there is no need to cope with the changes in the "Multi-series object creation", there is no need to use the abstract factory mode. In this case, a simple static factory is enough.
A series object refers to the relationship between these objects, such as the dependency between "road" and "House" in game development scenarios, "road" and "authentic" dependencies.
Abstract Factory patterns are often combined with factory method patterns to cope with the changes in "Object creation" requirements.
Generally, an instance of a specific factory class is created at runtime. The creation of a specific factory has a specific implementation product object. To create different product objects, the customer should use different specific factories.
The factory is used as a single piece. In an application, generally each product series only needs a specific factory instance. Therefore, the factory is usually best implemented as a single piece mode.
- Summary
The abstract factory mode provides an interface for creating a series of related or mutually dependent objects. The key point of using the abstract factory mode is to cope with the demand changes of "Multi-series object creation. In a word, you will understand the abstract factory model.OOPEssence: interface-oriented programming.
- For details, see
Http://terrylee.cnblogs.com/archive/2005/12/13/295965.html
5. Builder Mode
- Concept
Separates the construction of a complex object from its representation, so that different representations can be created during the same construction process.
- Applicable scenarios
When creating complex objects, the building sequence of the internal components of these objects is stable, but the internal components of the objects are subject to complex changes.
TheAlgorithmIs independent of the components of the object and the Assembly Method of the components.
- For details, see
Http://www.cnblogs.com/BeyondAnyTime/archive/2012/07/19/2599980.html
6. prototype mode
- Intention
Create an object instance by copying a prototype object
- Note:
Because when using the prototype mode, each class must have a clone method. If there is no good planning at the beginning of the class design, it may be very troublesome to think about cloning after a long time of use, especially when designing deep replication, this is because many factors are involved and the workload is huge.
- For details, see
Http://www.cnblogs.com/guoshiandroid/archive/2010/07/03/1770357.html