Refresh design pattern

Years later, again read the design pattern books, summarized the main points of each mode of this need itself has a certain model based design, combined with elements to help better understand and use.

  • Strategy Mode (Strategy)
    • Additional features different individual abstract interfaces
    • Function introduced in combination abstract class
    • Abstract class encapsulates each function module call
    • Implementation class may be arranged in the configuration functions embodied
  • Mode observer (Observer)
    • Subscribers are held by all subscribers
    • Data can be updated directly push
    • Data can also be updated to take notice Bengal
    • To a large extent decoupled from the observer and the subscribers
  • Decorator (the Decorator)
    • Simple implementation of an interface called decorator components
    • Holding component object is called a decorator
    • The decor is starting from the inner layer of the decorator
    • Innermost decorators will have the original components
    • The completion of the so-called decorative layers of packaging by the underlying object of the hold and return to the top
    • In theory one can do one set of endless
  • Method mode factory (Factory Method)
    • Implementation and use of decoupling products
    • Products need to abstraction
    • Factory method to create products defined interfaces
    • The method may further encapsulated within a factory during use
    • Child workshop configure your own creation logic
    • A method often used in conjunction with the abstract factory workshop
    • Abstract factory to create a defined group of products
    • Implement the factory method to create and use these products or components of large specific products
    • Factory methods to achieve through inheritance
    • Abstract factory to achieve (pass) by combining
  • Singleton pattern (the Singleton)
    • Note that global instance memory
    • Multithreading needs special care
  • Command Mode (Command)
    • Decoupling execution requester and the requester hair
    • Internal commands can be executed directly to the agent may also be encapsulated, including the recipient
    • Undo command support
    • Macros contain multiple commands at the same time call
  • Adapter mode (Adapter)
    • Object adapter combination thereof
    • Class adapter to achieve multiple inheritance
    • Old and new systems adapted to bi-directionally common
  • Appearance mode (the Facade)
    • From the level of abstraction and look like adapter
    • The appearance of a simple interface to create a new pattern
    • Adapter mode using existing interfaces
    • A new interface module packaging more simplified system calls
    • The old interface to other systems to achieve compatible packaging
  • Template Method pattern (Template Method)
    • Template algorithm, sub-class implementation steps
    • Child and parent class is not possible to form a ring
    • Hollywood model for the whole sub-category for the callback method
    • There is a default implementation of the hook method
    • Policy package with a combination algorithm, template inheritance encapsulation algorithm
    • Factory method is a special template method
  • Iterator pattern (Iterator)
    • Decoupling walk the array rather than specific types of care
    • Collections has its own iterator
    • Iterator general method next includes two hasNext
    • Aggregator holds data and create an iterator
  • Combined mode (Composite)
    • Mode combination of nodes and leaf nodes into sub-node
    • Child and leaves have achieved the same combination of interfaces, so-called transparency
    • Add child nodes to achieve and get extra
    • In order to secure the leaf nodes may also have different interfaces
    • Combined mode can coexist with iterator
    • Iterators need to meet the stack to achieve tree traversal
    • The child nodes may be implemented to reduce the empty iterator Null Analyzing
  • Mode state (State)
    • Similar to FIG class policy mode
    • Status interface defines the behavior state switching
    • All states implement unified interface
    • The state machine is defined and hold all states
    • Save the current state of the state machine
    • State switching is controlled by their different states
    • Switched by holding next state within the state machine state
  • Agent mode (Proxy)
    • It can be divided into remote agent and Alerts
    • Much like the decorator
    • Acting more of a real object access control, decoupling customers with real objects, it may help to create real objects
    • More decorator is to increase the behavior, and do not create objects
    • Plant body can be returned by the agent -
    • Much like the adapter
    • Agent does not change the interface, change the interface adapter
    • Protection agent can limit access to part of the interface, like adapter
  • Composite mode (the Compound)
    • Several multi-purpose
    • For example, MVC on the integration strategy, portfolio, adapters, etc.

  • Some popular mode

  • Bridge mode (Bridge)
    • Much like the strategy pattern
    • The main rely on abstract functional components
    • The main strategy is to achieve a specific mode algorithm
    • Host bridge mode more abstract subclasses need to implement different algorithms
    • The main functional components can be done and decoupling
    • Increased complexity
  • Generator (Builder)
    • The creation of complex objects package
    • Internal hide implementation
    • Need to have more knowledge of the object is created when the record
  • Chain of Responsibility (Resposibility)
    • Simply understood as a chain of objects of Handler
    • For example, many programs in common Dispatcher chain
    • Or many systems need to be loaded at startup data link
    • We can not guarantee that there will be an object for data processing
  • Flyweight (Flyweight)
    • Examples of the plurality of the same may be a control method, the polling can be packaged together array processing
    • But we can not separate the different behavior
  • Interpreter (Interpreter)
    • Mainly to do simple fixed parsing
    • Abstract interpretation interface and implement multiple interpreters
    • Such as And, Or and the like, can be nested within each other.
    • If the syntax complexity and diversity, it will not fit
  • Mediator (Mediator)
    • Decoupling different objects
    • They only need to inform the mediator, the mediator controls the entire logic state depending
    • Mediator may make overly complex logic
  • Memorandum (Momento)
    • The object store it out, better maintenance business of cohesion
    • Typically provide storage and access interfaces
    • Storage process can be time-consuming
    • You may need to consider serialization
  • Prototype (Prototype)
    • Provide a copy of the object method
    • For example, clone
    • If the object level deep copy can be complex
  • Visitors (Visitor)
    • Decoupled operation of each specific target object, such as the different components of the computer different operations
    • Small changes in the type of the object changes when using large operations
    • Each object implements the visitor interface to accept (accept) a visitor, and pass their own visitor (visit)
    • The disadvantage is that visitors are exposed to specific elements, rather than an abstract interface

There are many classifications, not rigidly stick can also be ignored.

  • I classification
    • Creating type
      • Singleton
      • Abstract Factory
      • Factory Method
      • Builder
      • prototype
    • Behavioral
      • Template Method
      • Iterator
      • status
      • Tactics
      • Observer
      • command
      • Interpreter
      • Mediator
      • Visitors
      • memorandum
      • Chain of Responsibility
    • Structural
      • Decorator
      • proxy
      • Exterior
      • combination
      • adapter
      • bridging
      • Flyweight
  • Classification II
    • class
      • Template Method
      • Factory Method
      • adapter
      • Interpreter
    • Objects
      • Singleton
      • Abstract Factory
      • Decorator
      • proxy
      • Exterior
      • combination
      • adapter
      • Iterator
      • status
      • Tactics
      • Observer
      • command
      • bridging
      • Flyweight
      • Builder
      • Mediator
      • Visitors
      • memorandum
      • Chain of Responsibility
      • prototype

Guess you like

Origin www.cnblogs.com/mengdd/p/refresh-design-pattern.html