Create mode
Abstract factory --- abstract factory
Definition: Provide an interface to create a series of related or interdependent objects without specifying their specific class usage frequency:
Using Scenario: Happyfather and Happermother quarreled, Happyfather went home to find a note "Do housework", so happyfather started the floor, brush the toilet, packing the room, cooking, enough for a few hours, finally Understand the hardships of HAPPYMOTHER: "Do housework" is equivalent to abstract factory, and HappyFather is based on it. Other applications: Simply call the abstract factory in the system or class library of multiple products, you can create The sub-part of the need to be implemented: Definition of the build of a complex object is separated from his representation, making the same build process can create different representations. usage frequency:
Use scenario:
Happymother is very strange why happyfather can make clothes to stain, sweat, blood stains, so dirty clothes should be washed first, then they can put them together in the washing machine
Scenario explanation: The various components of a complex object are created separately, and a part of the machine is washed and part of the hand wash (complex part) for the washing suit. The difference between the abstract factory is to return only one object, and the abstract factory returns a series Related objects Factory method --- factory method
Definition: Define an interface for creating an object, let the subclass determine which class, Factory Method makes a class's instantiation to the subclass usage frequency:
Using Scenario: Everyday is the day of Happy family celebration, because this day is a day of happyfather payment, Happyfather: "You do the rice today" happymother: "The meat is more incense, my son is more money. This month's zero flowers! "Happyfather:" Remember to go online online, the place always catching "Scenario: Happymother gives Happy Money to Happyson as the flower, buy something is made by Happyson.
Prototype --- prototype
Definition: Specify the type of object to create an object with a prototype instance, and create a new object using the new object using the prototype:
Use scenario:
Happymother: "I have to buy vegetables, wash vegetables, and fried vegetables every day. I have been done."
Happyfather: "Wife recently started to supply vegetables platter, all kinds of vegetables have been matched, I went to buy a piece of three fresh, a fish fragrant pork, buy it back and stir, it is very convenient."
Happymother: "I like it!"
Scenario explanation: Various vegetables platter is the prototype of cooking, stir fry, you can eat the application point: prototype clone itself, create new object Singleton --- single piece
Definition: Ensure that a class has only one instance and provides a frequency of accessing his global access point:
Use scenario:
Happyfather: "The son does not give this!"
Happyson: "What is Dad?"
Happyfather: "This is the housekeeping book of the family. It is only my account page. Later, it added your mother's account page. Later, it added your account page, and later added your son, the son's grandson. Submetry Sunshun ... "Scenario Explanation: The whole family has only one account book, access it to other applications by adding the account page: counter, shopping cart structure mode Adapter ---- Adapter
Definition: Convert a class to another interface that customers want, the Adapter mode allows you to work with those classes that are not compatible without compatibility. usage frequency:
Use scenario:
Time: HAPPYMOTHER during 1960: "His dad, the child is going to school, but there is no such thing as a good thing" happyfather: "Is there any way! Rice is not enough to have money to buy clothes, otherwise You change my clothes! "Happymother:" Good idea! "Xu Happyfather's clothes were changed to the HAPPYSON's clothes: Happyfather's clothes Cropped into a new clothes of HAPPYSON's new clothes: Pixabay: Adapter is suitable for existing classes, but the interface does not match. Bridge --- bridge
Definition: Separate the abstraction section with its implementation portion so that they can use the frequency of independently:
Using Scenario: Happy: Mother: "You said that it is responsible for sweeping the room but only sweeping the floor, you said that you cook, you are selling out, you said that you will play a lot of trouble every morning" happyfather: "You also know that I always said A set of a set of "scenario explanation:" Say "is an abstract part and" do "phase separation application points: abstract and realizes part in separate class hierarchy Composite --- Combination mode
Definition: Combine the object into a tree structure to represent a partial overall relationship, Composite makes the user with consistency usage frequencies for a single object and combined object:
Use scenario:
Happyson is two years old
Happymother told happyfather: "If the son does not sleep, you can sing him, you can sway him, you can sway while singing."
"" I don't want my father to shake, follow the mountain car "
Scenario explanation: There are many ways to sleep, you can also use several methods to use, all methods can be dealt.
Application points: The combination portion can be called like a single object, such as traverse the tree structure.
Decrator --- Decoration
Definition: Dynamic gives an additional additional responsibility to an object, in addition, Decorator mode is more flexible compared to generator
usage frequency:
Use scenario:
Time: 2003 During Sumdon
Happyfather: "Wife, how do you embroidered on my mask?"
Happymother: "Such a mask can not only prevent the virus is still beautiful."
Happyfather: "Why do you want to embroidery? Don't kiss me '.
Happymother: "Remind the car driver not to hit you"
Scenario explanation: Additional function is added to masks
Application points: embed the components into the object rather than the inheritance mechanism
Façade --- appearance
Definition: Provide a consistent interface for a set of interfaces in the subsystem, Façade provides a high-level interface, which makes the subsystem easier to use
usage frequency:
Use scenario:
Because Happyfather and Happyson indulgent eat two fat piers, Happymother locks the refrigerator in a room, and the grandfather can only eat all kinds of snacks through Happymother. However, Happymother is responsible for errands, and the grandfather is not comfortable. Scenario explanation: Happymother is similar to the interface of Happy Father and Son. HAPPY father and son simply told her to apply the application point: reduce the coupling of client programs and subsystems Flyweight- Enjoy Yuan
usage frequency:
Use Scenario: "HAPPYMOTHER:" HAPPYMOTHER: "HAPPYMOTHER:" HAPPYMOTHER: "HAPPYFATHER:" is the use of shared technology to effectively support a lot of fine-grained objects "happymother:" That cup is not Calculate? You can use tea, coffee, and you can do your hidden "happyfather:" ... "mode explanation: Cup as a shared object, you can use it in different scenarios, just According to its external state, the effect of different application points: the internal and external state of the object, applied to different scenarios according to different external states to achieve the shared object proxy --- agent
Definition: Provide a proxy for other objects to control access to this object:
Use scenario:
HAPPYSON School President's Office: "You have to teach your son, he fights in the school and classmates" happyfather: "The little child is playing is very normal." President: "Telling someone else. However, he cried my son "happyfather:"! Sorry, go home, I must learn, "Happyfather returned home," I told you to remember, the next time I don't want to fight the principal. " "Scenario] HAPPYFATHER is a HAPPYSON guardian is also a proxy application point: Proxy only provides access to entities, entity definitions of key features.