Create a schema five kinds (2)

The main focus is to create a schema of "How to create an object?", Its main feature is "the creation and use of objects of separation."
Users do not need to focus on the details of creating objects, create objects to complete by the relevant plant. Like when we go to the mall to buy goods, you do not need to know how goods are produced by the same, because they are produced by specialized manufacturers.


1. Singleton (Singleton) mode:
          in a computer system, as well as the Windows Recycle Bin, operating system, file system, multiple threads in the thread pool, the graphics card driver object, the printer spooler service, application log objects, database connection pooling, counter site, Web application configuration object, the application dialog system caching often designed to single embodiment.

2. Prototype (the Prototype) mode:
         In some systems, the presence of large number of identical or similar object create problems, if a conventional constructor to create an object, it would be more complicated and time-consuming and resource, it is an object prototype model generation efficiency like the monkey King monkey unplug the hair gently blowing becomes as easy as a lot of the monkey King.
         For example, Windows operating system installation usually more time-consuming, if you copy a lot faster.

3. factory method (FactoryMethod) mode:
        If you want to create much of the product, as long as a factory class can be completed, this mode is called "simple factory pattern," it is not part of the 23 classic GoF design patterns, it has the disadvantage It would be contrary to "the principle of opening and closing" when adding new products.
        There are a variety of products specialized factory.
        Different kind of factory production of different products. Plant A, B respectively, produce a series of shampoo, shampoo b series.

4. Abstract Factory (AbstractFactory) mode:
        the factory method model only considers the production of the same level of product, but in real life, many factories are integrated factory, capable of producing multi-level (kind of) products, such as farm animals and raise both plants, electrical plants producing both television and production of washing machines or air conditioners, both universities have specialized software such as Biology.
        Same factory produce different products. A factory producing shampoo, shower gel and other products.

5. Builder (Builder) mode:
       the living room is the product, including walls, television and sofa components. Specific renovation workers are specific builder, they are responsible for the decoration and walls, TV and layout of the sofa. The project manager is the director, he was responsible for directing decorators renovation.

 

----------

Structure Mode

Example 1. Single-mode main character is as follows.

    Example 1. Single class: contains an instance of the class of the instance and can create their own.
    2. access classes: class using a single embodiment.


2. prototype model consists of the following major role.

    1. Prototype abstract class: specifies the interface must implement specific prototype object.
    2. Specific class prototype: Prototype abstract class implement the clone () method, which is copied object.
    3. access classes: using clone () method of class specific prototype to copy the new object.


3. The main role of the factory method pattern as follows.

    1. Abstract Factory (Abstract Factory): provides an interface to create a product, the caller access to the plant by its specific method newProduct factory () to create the product.
    2. Concrete Factory (ConcreteFactory): mainly the implementation of the abstract method in the abstract factory, complete the creation of specific products.
    3. abstract product (Product): defines the product specification, describes the main features and functionality of the product.
    4. Specific Products (ConcreteProduct): implements the interface defined roles abstract product, created by the concrete factory, which correspond with between concrete factory.


4. The main role of the abstract factory model are as follows.

    1. Abstract Factory (Abstract Factory): provides an interface to create a product that contains multiple methods newProduct create products (), you can create several different grades of products.
    2. Specific factory (Concrete Factory): The main is to achieve more abstract methods in the abstract factory, complete the creation of specific products.
    3. Abstract product (Product): product specification defines, describes the main characteristics and functionality, there are a plurality of abstract factory model abstract products.
    4. Specific Products (ConcreteProduct): implements the interface defined roles abstract product, created by the specific plant, it is the same relationship between the many-to-concrete factory.


The main character builder (Builder) mode are as follows.

    1. Product role (Product): It is a complex object that contains multiple components, and off to create its various components by a particular builder.
    2. Abstract builder (Builder): It is an abstract method includes creating various subcomponents of the product interface, typically also contain a complex product process returns getResult ().
    3. Specific builder (Concrete Builder): Interface Builder achieve, accomplish specific method of creating the various components of complex products.
    4. director (Director): it calls the member structure and assembling method of an object is completed builder to create complex objects, does not relate to specific product information in the commander.

Guess you like

Origin www.cnblogs.com/zzlcome/p/11076417.html