Synopsis common design patterns

  More commonly used method of a factory design pattern mode, single-mode embodiment, the appearance model, the observer pattern, proxy mode, the adapter mode.

Defines a factory method (FactoryMethod) mode: the definition of a product created object factory interface, the actual creation of the work product to the delayed object factory class among specific sub. This satisfies the characteristics required to create the schema in "Creating and using a phase separation".

The main role of the factory method pattern is 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.

 

Second, the definition singleton (the Singleton) mode: refers to only one instance of a class, and the class to create a model of the instance itself. For example, Windows can only open a task manager, which can be avoided by opening multiple windows task manager and a waste of memory resources, or display the contents of each window appears inconsistent and so wrong.

Singleton has three characteristics:

  1. EXAMPLE only a single instance of the object class;
  2. The singleton object created by the Self singleton;
  3. Singleton class provide external access a single global access point of the embodiment;

 

 

Third, define the appearance (the Facade) mode: by providing a consistent interface to a plurality of complex subsystems, the mode of the subsystems to be accessed more easily. The model has a unified interface to the external, external applications do not care about the specific details of the internal subsystems, it would greatly reduce the complexity of the application, improve the maintainability of the program.

Appearance (Facade) model consists of the following major role.

  1. Appearance (Facade) role: to provide a common multiple of external interface subsystem.
  2. Subsystem (Sub System) role: to achieve part of the system functions, customers can access it through the appearance of the characters.
  3. Customer (Client) Role: access by various subsystems of the appearance of a role.

 

 

Fourth, the viewer is defined (Observer) mode: refers to the presence of many dependencies among a plurality of objects, when a state of the object changes, all objects that depend on it have been notified and updated automatically. This mode is sometimes referred to publish - subscribe model, model - view mode, it is the object behavioral patterns.

The main role of the observer mode are as follows.

  1. Abstract topics (Subject) Role: also known as an abstract object classes, which provides aggregation and increase class to hold a viewer object, delete observer object methods, abstract methods and notification of all observers.
  2. Specific topics (Concrete Subject) Role: also known as specific target class that implements the abstract goal of the notification method, when the internal state specific theme changes, notify all registered observers object.
  3. Abstract observer (Observer) role: it is an abstract class or interface, which includes an updated his abstract method, when receiving change notification specific theme is called.
  4. Specific observer (Concrete Observer) roles: the abstract methods defined in the abstract observer implemented in order to update their status when obtaining change notification goals.

 

 

Fifth, the definition of proxy mode: for some reason you need an object to provide a proxy to control access to the object. In this case, the object does not fit or can not access a direct reference to the target object, a proxy object as an intermediary between the access and target objects.

The main role of the agency model as follows.

  1. Abstract topics (Subject) categories: real business methods and themes proxy object achieved by the interface or abstract class declaration.
  2. Real theme (Real Subject) category: abstract achieve specific business topics, real object is represented by a proxy object, the object is to be the ultimate reference.
  3. Proxy (Proxy) class: provides the same interface with the real theme, the interior contains a reference to the real subject, it can access, control, or extend the functionality of the real theme.

 

 Six custom adapter mode (Adapter) as follows: converting a class interface clients expect another interface, such as those due to incompatible interfaces based otherwise not able to work together with the work. Adapter mode is divided into mode-based structural and structural objects two modes, coupling between the former than the latter category, a programmer is required and the internal structure of the conventional component library related components, it is relatively seldom used some.

1. Structure Model

Adapter mode (Adapter) contains the following major role.

  1. Target (Target) Interface: the current system of business expected interface, which can be abstract classes or interfaces.
  2. Fitter (the Adaptee) Class: it is being accessed and an interface component adapted existing component library.
  3. Adapter (Adapter) class: it is a converter, by inheritance or referenced objects fitter and fitter conversion interface into the target interface, according to the destination interface to allow customers to access the adapter's format.

 

 

 

 

See http://c.biancheng.net/view/1317.html

 

Guess you like

Origin www.cnblogs.com/taitai139/p/11762530.html