Have not been very familiar with design patterns, and do not know how to use. Now slowly 1.1 to understand.
Create Pattern: Factory method mode, abstract Factory mode, singleton mode, builder mode, prototype mode structured mode: Adapter mode, decorator mode, proxy mode, appearance mode, bridging mode, combined mode, and enjoy meta mode behavioral mode: Policy mode, template method mode, observer pattern, iteration sub-pattern, There are two types of responsibility chain mode, Command mode, Memo mode, state mode, visitor mode, mediator mode, and interpreter mode: concurrency mode and thread pool mode.
policy mode : Different behavior, same interface, Environment decides to use that kind of behavior
Strategy mode: Boys chasing girls, the result is the same, most of the chase, but the strategy is not the same, how to catch up with girls? That's a good strategy.
prototype mode : Clone, same data, different object
Monkey King has a special skill, is to pull with monkey hair can become a Monkey king, the Monkey King and the real Monkey King is the same as long, but they are different objects.
Application scenario: Mainly used to copy data from complex structure objects
Responsibility chain Model
Enables multiple objects to have the opportunity to process requests, thus avoiding the coupling between the sender and the recipient of the request.
Link the object to a chain and pass the request along the chain until an object is processed by him.
Role
Abstract processor Role (Handler): Defines an interface for processing requests. If necessary, the interface can define a method to set and return a reference to the home. This role is typically implemented by a Java abstract class or Java interface.
Specific processor role (Concretehandler): When a specific processor receives a request, it can choose to dispose of the request or pass the request to the other person. As the specific processor holds references to the homes, the specific processor can access the homes if necessary.
Application Example: Filter chain and Interceptor chain.
template mode : fixed process
Packagetemplate;//Punch the drinks (take them out and sell them) Public Abstract classBevegrage {//cannot be rewritten Public Final voidCreate () {//1. Boil the waterBoilwater ();//2. Prepare the cups and put the ingredients into the cups .Pourincup ();//3, Water brewingBrew ();//4, add accessoriesaddcoundiments ();} Public Abstract voidPourincup (); Public Abstract voidaddcoundiments (); Public voidBrew () {System.out.println ("Pour boiling water into a cup for brewing");}; Public voidBoilwater () {System.out.println ("Boiling water, burning to 100 degrees can make a pot.");}}
Different implementation classes implement the Pourincup and Addcoundiments methods.
Viewer mode:
The application scenario of the Observer pattern: <1> an update to an object state requires another object to synchronize updates, or an update to an object that relies on another object's update; the <2>. Object only needs to notify its own updates to other objects without needing to know the details of other objects. such as message pushes.
Practical application: The Observer pattern can also be used in the network of clients and servers, such as mobile phone applications of the message push, the server is the Observer, each mobile app is the observer, once the data on the servers (such as app upgrade information) has been updated, will be pushed to the mobile phone client.
Class Diagram:
Java Design Patterns