Chasing MM and Java 23 design modes

zhaozj2021-02-16  46

[Created mode]

1, Factory- Chasing MM, you can't eat, please eat, McDonald's chicken wings and KFC's chicken wings are things that MM love to eat, although the taste is different, no matter you go to McDonald's or KFC, only to wait for the waiter " The chicken wings "will. McDonald's and KFC is Factory that produces chicken wings

Factory model: Customer class and factory class separate. Consumers need some kind of product at any time, just request the factory. Consumers can accept new products without modification. The disadvantage is that when the product is modified, the factory class must make a corresponding revision. Such as: How to create and how to provide it to the client.

2, Builder-MM's favorite listening is "I love you" this sentence, see MM of different places, you must use their dialect to tell her this sentence, I have a variety of language translator, Each language has a button. When I see MM, I can use the corresponding key. It can use the corresponding language to say "I love you" this sentence, the foreign mm can also make it easy, this is me "I love you" builder. (This is certain than the US military translator used in Iraq.

Construction mode: Split the internal representation of the product and the generation process of the product, thereby generating a product object with different internal representations. The construction model makes the internal representation of the product can change independently, and customers do not have to know the details of the internal composition of the product. Construction mode can enforce the construction process of a sub-step.

3, Factory Method - Please go to McDonald's to eat burger, different mm has different tastes, you have to remember is an annoying thing, I usually use the Factory Method mode, with MM to waiter, say " A burger, what kind of burger is the specific burger, let MM say directly to the waiter.

Factory Mode: The core factory is no longer responsible for the creation of all products, but will give the specific created work to the subclass, become an abstract factory role, only responsible for the interface that must be implemented, not contact Which product class should be instantiated.

4, prototype, chat with MM, must say some affection, I have collected a lot of meat love words, when you need COPY, you will go in QQ, this is my love. Prototype. (100 yuan, do you want to be)

Original model mode: By giving a prototype object to specify the type of object to be created, then create more types of objects with the method of copying this prototype object. The original model mode allows the dynamic to increase or decrease the product class, and the product class does not require any level of prior defined, the original model mode applies to any level structure. The disadvantage is that every class must be equipped with a cloning method.

5, Singleton - I have 6 beautiful wife, their husband is me, I am the husband sigleton in our family, as long as they say "husband", they all refer to the same person, that is, I have just a dream. Oh, how can you have such a good thing?

Single-case mode: Single-case mode Make sure that a certain class has only one instance, and it is instantiated and supplied to the entire system. Single example mode should only be used when there is a real "single instance".

[Structure mode]

6, Adapter - I met a beautiful Sarah in a friend party. From Hong Kong, I won't speak Cantonese. She will not speak Mandarin, I have to help my friend Kent, he as the adapter between me and Sarah. Let me talk to each other and Sarah (I don't know if he will play me)

Adapter (Transformer) mode: transforms a class interface into another interface to the client expectation, so that two classes that originally do not match the reasons for interfaces cannot work together. The adaptation class can return a suitable instance to the client based on the parameter. 7, Bridge- I met MM in the morning, I have to say good morning, I have encountered MM in the evening, I have to say good evening; I have to wear new clothes, I want to say that your clothes are so beautiful, I've encountered MM new hairstyle, To say your hair is so beautiful. Don't ask me "I have a new MM in the morning, how to say", "I can't use the bridge combination.

Bridge mode: Differentialization of abstraction and implementation make the two can change independently, that is, the strong correlation between them becomes weakly associated, that is, refers to the abstraction and implementation of a software system. The combination / polymeric relationship is used instead of inheritance, so that both can change independently.

8, Composite-Mary has a birthday today. "I have a birthday, you have to send me a gift." "Well, ok, go to the store, you will pick it." "This T-shirt is very beautiful, bought, this dress is good, buy, this package is also good, I bought it. "" Hey, I bought three pieces, I only promised to send a gift. "" What, T-shirt plus skirt plus bag, just match a set, Miss, trouble you. " "...", MM will use the Composite mode, have you?

Synthesis mode: The synthesis mode will be organized into the tree structure and can be used to describe the overall relationship between the overall and part. The synthesis mode is a mode of processing a tree structure of an object. The synthesis pattern expressed the structure of the part and the entire relationship. The synthesis pattern allows the client to treat a separate component object and synthetic objects composed by them.

9, Decorator-Mary overtime to SARLY birthday, still don't tell her to pick it up, otherwise this month's food fees will definitely have finished playing, take out the photos I took photos in Huashan last year, and write "the best The gift is to love your fita. "After buying a gift shop to the street (the mm of selling gifts is also very beautiful), then find a beautiful box to put it up ..., We are all Decorator, and eventually modify me this person, how do you understand?

Decorative mode: Decorative mode to extend the function of the object in a transparent manner, is an alternative to inheritance relationships, providing more flexibility than inheriting. Dynamically give an object increasing function, which can be revoked again. Increase a very large number of functions generated by some basic functions.

10, Facade - I have a professional Nikon camera, I like it yourself to adjust the aperture, the shutter, this photo is special, but MM does not understand these, and I will not teach for a long time. Fortunately, the camera has a FACADE design mode, adjust the camera to the automatic file, as long as the target is on the shutter, everything is automatically adjusted by the camera so that MM can also take this camera to take pictures.

Facade mode: Communication with an external and a subsystem must be performed through a unified facade object. The facade model provides a high-level interface that makes the subsystem easier to use. Each subsystem has only one facade class, and this facade class has only one instance, that is, it is a single case mode. But the entire system can have multiple facade classes.

11, Flyweight- Send a text message with MM every day, the fingers are exhausted, recently bought a new mobile phone, can put some common sentences, when you want to use, take it out, add MM's name You can send it, no longer use a word one word. The shared sentence is Flyweight, the name of the mm is the external feature extracted, according to the context. Enjoying Yuan Mode: Flyweight refers to the most exclusive level in the boxing competition. Enjoying Yuan mode is efficiently supported by sharing to support a large number of fine granular objects. The key to enjoying the element can be shared is to distinguish between the intrinsic state and the external state. The inherent state is stored inside the enjoys and does not vary with the environment. The outer state is changed as the environment changes. The outer state cannot affect the intrinsic state, which is independent of each other. The state that will be shared and the state that cannot be shared is distinguished from the conventional class, and the status of the shared cannot be shared from the class. The client cannot create a shared object directly, and a factory object should be used to create a shared object. The enjoyment mode greatly reduces the number of objects in memory.

12, proxy - chat with MM online, one start "Hi, Hello", "Where did you come?" "How old?" "How much is it?" These words, it is really annoyed, write a program As my proxy, all have the answer to these words, set the automatic answer, and let me know if you receive other words, how to answer, cool.

Proxy mode: Agent mode provides a proxy object to an object and controls the reference to the source object by the proxy object. The agent is a person or a body represents another person or an institution. In some cases, customers don't want to directly reference an object, and the agent object can directly play directly to the intermediary directly. The client does not have a proxy topic object with the real subject object. The proxy model can do not know the true subject object, but only one interface of the agent object, at this time, the agent object cannot be created by the agent object, and the other role that must be available in the system is created and incorporated.

[Behavior mode]

13, CHAIN ​​of Responsibleity - go to the English lesson at night, in order to soon, I sat in the last row, wow, I took a few beautiful MMs, find a note, write "Hi, can be my girlfriend Do you want to pass forward?

Responsible chain mode: In the responsible chain mode, many objects are connected by each object.

Get together to form a chain. Requests on this chain until an object on the chain decides to handle this request. Customers don't know which object on the chain finally processes this request, and the system can reorganize the chain and assignment responsibility without affecting the client. There are two options: responsibility or push the responsibility to the next home. A request can eventually be accepted by any receiving end object.

14, Command - I have a MM home to manage very strict, I can't meet, I have to use her younger brother to transfer information between us, what is her instruction to me, write a note to bring me brother? . This is not, her brother passed another Command. In order to thank him, I invited him to eat a bowl of soy sauce, and where he said: "I will send my sister three boyfriend to Command, as you have the minimum gas, Please eat face. "

Command mode: Command mode encapsulates a request or operation into an object. Command mode The responsibility of the issued command and the responsibility of executing commands are separated, and delegate different objects. The command pattern allows the request to be opened independently, so that one of the requests does not have to know the interface to receive the request, it is not necessary to know how the request is received, and when is executed, when is executed, how to be executed of. The system supports the undo. 15. Interpreter - There is a "Bubble MM Truth", there are various strategies of various MMs, such as the steps to eat Western food, go to the movie method, etc., as long as the MM, as long as I do Interpreter, photo The above script is executed.

Interpreter mode: After a given language, the interpreter mode can define a representation of its grammar and provide an interpreter. The client can use this interpreter to explain the sentence in this language. The interpreter mode will describe how to use the mode design to explain these statements when there is a simple grammatist. The language mentioned in the interpreter mode means any combination of any interpreter object. In the interpreter mode, you need to define a level structure of a command class that represents a text method, that is, a series of combined rules. Each command object has an interpretation method that represents an explanation of the command object. Any arrangement combination of objects in the level of command objects is a language.

16, Iterator - I love Mary, regardless of everything to marry her.

Mary: "I want to marry you, I have to promise me"

Me: "What conditions I have promised, you said,"

Mary: "I look at the one-grade diamond"

I: "I bought, I bought, still?"

Mary: "I look at the villa of the lake."

I: "I bought, I bought, still?"

Mary: "I look at the Ferrari sports car"

My head is awkward, sitting on the chair, a bit bite: "I bought, I bought, is there?"

......

Iterative Submount: Iterative Submount can sequentially access a gathering element without exposing the gathered internal appearance. The generally referred to as a gathering of multiple objects is aggregated, and the aggregation target is a container object that can contain a set of objects. Iterative Submatings encapsulate iteration logic into a separate sub-object to separate from the aggregate itself. The iterative sub-mode simplifies the interface of the aggregation. Each of the aggregated objects can have one or more iterative sub-objects, each iterative state of each iterative, can be independent of each other. The iterative algorithm can be independent of the aggregated role.

17, Mediator - four mm playing mahjong, who should give each other, how much money is unclear, fortunately, I am next, according to the individual chips, earn money from me, lose money I also paid it to me, everything is OK, I got four MM phone.

Turpler mode: The mediation mode is packaged in a series of objects to interact, so that these objects do not have to make each other. This allows them to loose coupling. When the role between some objects changes, there is no immediate impact on other objects. Ensure that these roles can be different from each other. The mediation mode converts multiple interactions into a pair of interactions. The mediation mode is abstracted by the behavior of the object and collaboration, and the object is separated from the interaction of other objects in small scales.

18, MEMENTO, when chatting with a few MM, must remember what I just said with MM, otherwise MM discovers will not be happy, fortunately, I have a memo. Which mm said, what I said? All copied a copy in the memo, so you can read the previous record.

Memo mode: Memorandum object is an object that is used to store a snapshot of another object's internal state. The purpose of the memo mode is to catch the state of an object without damaging the package, and is external, stored, so that this object can be restored to the stored state when appropriate. 19, Observer - want to know the latest MM intelligence of our company? Joined the company's MM intelligence mail group, Tom is responsible for collecting information, and the new information he discovers does not need to notify us, directly publish it to the mail group, we can send an intelligence in time as a subscriber (observer)

Observer mode: The observer model defines a team of multi-dependent relationships, so that multiple observer objects listen simultaneously with a topic. When this topic is changed, all observer objects will be notified to enable them to automatically update themselves.

20, State - When interested with MM, be sure to pay attention to her state. Her behavior will be different in different states. For example, you will go to watch movies this evening, and MM, which is not interested, will say "there is Things, "I don't hate it, but I haven't liked MM" good, but can I bring my colleague? ", I have already said that your MM will say" What time? After watching the movie again How about going to the bubble? ", Of course, you can see a good performance during the movie, or you can never like to become like it.

Status mode: The status mode allows an object to change behavior when its internal state changes. This object looks like a class that changes it. Status mode Pack the behavior of the objects in different status objects, each state object belongs to a subclass of an abstract state class. The intent of the state mode is to make an object change in its internal state change. The status mode requires a subclass of a status class for each system possible. When the status of the system changes, the system changes the selected subclass.

21, Strategy - Dating with different types of MM, to use different strategies, some, please make a movie better, some, eat the snack effect, some go to the seaside romance, single goal is to get MM's Fang Xin I have a lot of strategy in my chasing mm kit.

Policy Mode: Policy mode For a set of algorithms, each algorithm is encapsulated into an independent class with a common interface, so that they can be replaced with each other. The policy mode makes the algorithm can change without affecting the client. Strategy mode separates behavior and the environment. Environmental class is responsible for maintaining and querying behavioral classes, and various algorithms are provided in specific policy classes. Due to the algorithm and the environment independently open, the algorithm is increased or decreased, and the modifications will not affect the environment and client.

22, Template Method - Have you seen this classic article? " Girls have divided the constant steps to the unchanging steps, break the deadlock, launch pursuit, kissing, ava play, hands, caress, go in Template Method, but each step is different, there is different situations. The practice, this is going to see you randomly strain (specific implementation);

Template Mode Mode: Template Method Prepare an abstract class, implement partial logic in the form of a specific method and the specific structure, and then declares some abstract methods to force subclands to achieve the remaining logic. Different subclasses can implement these abstraction methods in different ways, thereby different implementations of the remaining logic. A top logical framework is first developed, and the details of the logic will be made to the specific subclass.

23, Visitor - Valentine's Day, give each MM to send a bunch of flowers and a card, but each MM sent to the characteristics of her personal characteristics, each card should also pick it according to the characteristics of the individual, I A person is clear, or find a flower shop owner and gift shop owner to do Visitor, let the flower shop boss choose a bunch of flowers according to MM, so that the gift shop owner also chooses a card according to each person, so it is easy More; visitor mode: The purpose of the visitor mode is to encapsulate some operations applied to a certain data structure element. Once these operations need to be modified, the data structure that accepts this operation can remain unchanged. The visitor mode is applied to a system that is relatively unstuten data structure, which relieves the coupling between the data structure and the operation of the structure, so that the set of operations can evolve relatively free. The visitor model makes it easy to increase the new operation, add a new visitor class. The visitor mode sets the relevant behavior into an accessor object rather than scattered into a node class in one. When using the visitor mode, you should put as many objects as possible in the visitor class, not in its subclass. The visitor mode can accepted a member class that belongs to different level structures across several levels of hierarchy.

转载请注明原文地址:https://www.9cbs.com/read-21279.html

New Post(0)