we are at
Some software design patterns have been introduced in the previous article, and some non-software examples are given. Below, let's continue to complete the exploration of software design patterns to see behavioral patterns and instances in these modes.
Behavior mode
The author summed up the eleven behavioral model. These modes can find examples in coin classification banks, restaurant ordering, music, transportation, automotive repair, vending machines and home buildings.
CHAIN OF RESPONSIBILITY
The duties chain mode makes multiple objects have the opportunity to process the request, thereby avoiding the coupling relationship between the requested sender and the recipient. Mechanical coin sorting bank uses a duties chain. This is not assigned a slide for each coin, but only one slide is used. When the coin falls, the coin is guided by the inside of the bank to the appropriate receiving box.
Figure 13: Dog chain mode object map using a coin sorting example
Command (Command) mode
Command mode The request is packaged into an object, allowing you to use different requests to parameterize the customer. The bill when dining is an example of command mode. The waiter accepts the customer's order and records it on the bill. This order is queued to wait for cooking. Note that the "bill" here is not dependent on the menu, which can be used by different customers, so it can add different point items.
Interpreter
The interpreter mode defines a grammatist representation and interpretation of the grafting method. Musicians are examples of interpreters. The scale and its duration can be represented by the symbols on the five-tier spectrum. These symbols are music language [14]. The musicians can repeatedly reproduce the same music according to the music.
Iterator (Iterator)
The iterator provides a method sequence to access the individual elements in a collection object, and does not need to expose the internal representation of the object. In the early TV, a dial is used to change the channel. When the channel is changed, you need to manually turn the dial to move each channel, regardless of whether this channel has a signal. Now TV, use [next] and [previous] button. When the [Take one] button is pressed, it will switch to the next preset channel. Imagine watching TV in the hotel in a strange city. When changing the channel, it is important not a few channels, but the contents of the program. If you are not interested in a channel of a channel, you can replace a channel without knowing it is a few channels.
MEDIATOR
The intermediard mode uses a multi-aeration object to control a series of object interactions. The loose coupling between the individual objects is achieved by the intermediaries, not directly to each other. The control tower of the airport demonstrates this model. The plane that landed or take-off directly communicates with the tower instead of directly communicating with each other. Who can take off or landing is determined by the tower. It should be noted here that the tower does not control the entire flight process. It is only responsible for the area near the airport.
Figure 17: Mediator mode using the training center as an example
Memo (Memento)
The memo mode captures and saves an internal state of an object outside so that the object can be restored to the state. This model is usually reflected in the brakes of your own repairs. First remove the baffle on both sides, reveal the left and right brake pads. Only one piece can only be removed, then another piece is used as a memo to indicate how the brake is installed. After this repair is completed, you can remove it. When the second piece is removed, the first piece will become a memo.
Observer mode
The observer defines a pair of relationships between objects. When the status of an object changes, all objects that depend on its object are notified and automatically updated. Auction demonstrates this model. Each bidder has a brand label for bid. When the auctione starts auction, he observes whether there is a brand raised bid. Each time you accept a new bid, you have changed the current price of the auction and broadcast to all biders for new bids.
State mode
The status mode allows an object to change its behavior when its internal state changes. This model can be observed on the vending machine. The status of the vending machine includes a list of column list, payment, money to find money, and choice of goods. When putting a coin and selects a commodity, the vending machine can complete the following operations, including: sending out the goods do not find money, sending out the goods and finding money, because the coin is less than the goods, because the goods are not sent out of the goods. Strategy mode
Policy model defines a series of algorithms that can be replaced with each other. Different ways to go to the airport are examples of a policy mode. There are several options: driving themselves, take a taxi, take the airport shuttle, take a bus or use a car service, and so on. For some airports, subways and helicopters are also possible. Any way can you send you to the airport, which can be replaced with each other. You must make a choice based on price, convenience and time.
Template Method (Template Method)
The template method defines a skeleton of an operation algorithm and delays some steps into the subclass. The home architect is developing a twin thirst was 崾 0 宸 龅湫 龅湫 墓 婊 ㄒ ㄒ ┙ ㄖ 嫱 嫱 嫱 嫱 嫱 銎 銎 銎 銎 嫱 逑 逑 逑 逑 銎 銎 銎 嫱 嫱 嫱 嫱 嫱 嫱 嫱 嫱 嫱 嫱 嫱 銎 嫱 嫱 嫱 嫱 嫱 嫱 嫱嫱 嫱 校 鼗 ⒔ 峁埂 ⑸ ⑸ 滤 滤 涠 且 谎 谎 诮ㄖ 诮ㄖ 诮ㄖ 诮ㄖ 诮ㄖ 诮ㄖ 诮ㄖ 诮ㄖ 诮ㄖ 诮ㄖ 诮ㄖ 诮ㄖ 诮ㄖ ?
Visitor (Visitor)
The visitor mode represents an operation of each element in the object structure, defining this operation does not change the class of the element. This model can be observed in the operation of the taxi company. When a person called a taxi company, he (she) became a member of all the company's customers. The company then specifies a car to serve (accepting visitors). After entering the taxi, this person (visitor) no longer controls his (her) journey, but is responsible by the taxi (driver).
significance
Software design model has many non-software examples. Maybe some people want to know the practical significance of these examples. Non-software examples help enhance the expression of the pattern language and the learning of the auxiliary mode.
Increase the expression of mode language
Alexander feels that the real mode is integrated into a common language so everyone can share. In the population of software design, the pattern is considered to be a customized development method between colleagues. The mode provides a higher level of the module, process, and object.
An important factor in a language is the soul image corresponding to the language image. In a language, it is meaningful when a person can understand the meaning of a symbol. Alexander has no ignoring this important feature of the pattern language, which provides that a language is completely configured after the building type it produces can be specifically seen. In software design, Richle and Züllighoven recognize the importance of specific examples to guide us to understand the application.
If the software design pattern becomes a common language in the programmer, its foundation is a unified meaning. If the design decision is reached, it is not understood, and the designer is forced to complete the work through hypotheses. Oriented examples are more convenient to understand, the reason is that people must find the associated content in memory. In an AG Communication Systems company project, a non-software example is often used to interpret the relationship between modes. This example helps to provide a unified understanding between designers. By establish a unified understanding of the design process, the communication between the designers is easier in the entire project life cycle.
in conclusion