Explore software design modes (1)

xiaoxiao2021-03-06  91

Software design patterns are derived from the architecture model and object movement of Christopher Alexander. According to the view of Alexander, the mode is a repetition of a general solution itself for a particular system. Object movements are focused on the relationship between the real world is modeled as the internal relationship. Based on these two reasons, software design model should be repeated for objects of real-world objects. This article presents the non-software mode instance in the world, these models come from "Design Mode - Decisive Object Software" (DESIGN PATTERNS - Elements of Reusable Object-Oriented Software) [13] . This article also discusses the practice of mode language on non-software expressiveness and design patterns.

In the software industry, the group supporter's group is expanding. The origin of model development can be found in the work of architect Christopher Alexander. He believes that the model is a general solution in the world's specific system. The model he describes can be observed in daily buildings. Each mode in "a pattern language" contains a picture of the original example of this mode.

Although substances are the mainstream world's view, the model is believed in the software world, and the model also has the root cause of the development of things. Unfortunately, the example of software design patterns is not as rich as Alexander mode, because software design is exquisite ideas rather than those who originally generated. The proppiaibility of most software today limits our opportunity to exposure to first-class design.

According to Alexander, the model in the real world is always repeating yourself, because in a specific environment, they always adapt to existing environmental factors. In software, either the real world problem is completely modeled, or the real world object is converted into hardware and software to produce the results of the real world. Since the software design pattern is rooted in Alexander's style and object, it is normal to find software design patterns in the real world. This is not to say that the software design model is an inevitable model of real world things, but it is said that the relationship between the interaction between the actual object can be observed in the "real world" and software object. In order to verify this assumption, we will find an example of a real world for each design pattern.

Create mode

Author (referring to the authors of "design model" - summarizing five creation modes. Examples of creation modes can be found in manufacturing, fast food, biological and administrative agencies.

Abstract factory (Abstract Factory)

The purpose of the abstract factory is to provide an interface that creates a series of related or interdependent objects without having to specify the specific classes. This model can be found in the metal stamping equipment used in Japan's automobile manufacturing plants. This stamping device can make the car body part. The same machinery is used in the right door of different models, left door, right front fender, left front fender and hood, etc. By using a runner to change the punch plate, the specific class of this machine can be changed within three minutes.

Figure 1: Pressure example of abstract factory

Builder (Builder)

The generator mode is separated from the build of complex objects with the performance of the object, which makes the same build process can create different performance. This model is used for fast food store making children's meals. Typical children's meals include a staple food, a complementary food, a drink and a toy (such as hamburger, fried chicken, cola and toy car). These can be different in different child meals, but the process of combining children's meals is the same. Regardless of the customer point, it is the same as the three cure or chicken, the process is the same. The staff of the counter directly puts staple food, complementary food and toys. These are placed in a bag. The beverage is poured into the cup and placed outside the bag. These processes are the same in mutual competitive restaurants.

Figure 2: Object role of the generator mode using children meals as an example

Factory Method

Factory methods define an interface for creating an object, but which class makes subclasses to instantiate. Pressure is presented in this mode. Plastic toy manufacturer processes plastic powder to inject plastics into the mold that wants shape. The category of the toy (car, characters, etc.) is determined by the mold. Figure 3: Object map of factory methods using implantation formation

Prototype example

Prototype mode Use prototype instances to specify the type of creating objects. The prototype of the new product is usually established before all products. Such prototypes are passive and do not participate in copy itself. A cells have a mitosis, producing two same cells, an example of playing an active role to copy its own prototype, which demonstrates the prototype mode. A cell division produces two cells of the same genotype. In other words, the cells were cloned.

Figure 4: Prototype mode object map using cell split example

Singleton example

Single mode Make sure that a class has only one instance and provides a global access point access to it. Single mode is mimic monitors named, and the definition of a single set is that each collection contains only one element. The president of the US president is a single piece, the US constitution provides for the presidential election, term, and succession of the sequence. In this way, only a current president can be used at any time. Regardless of the current president, its title "President of the United States of America" ​​is a global access point for people who visit this position.

Figure 5: Single piece mode object map using the presidential example

Structural mode

The author summarizes seven structural modes. These modes can be found in tools, residential wirings, mathematics, holiday traditions, retail catalogs, and banking.

Adapter

Adapter mode allows you to convert a class's interface into another interface of the customer's expectation, so that you can work together because interfaces are not compatible and cannot work together. The wrench provides an example of an adapter. A hole is in ratchet, and the dimensions of each side of the ratchet is the same. In the US typical side length of 1/2 '' and 1/4 ''. Obviously, if a adapter is not used, the ratchet 1/2 '' ratchet is not suitable for 1/4 '' holes. A 1/2 '' to 1/4 '' adapter has a 1/2 '' shaped slot to set a 1/2 '' teeth, and there is a 1/4 cylinder to cartridge 1 / 4 '' wrench.

Figure 6: Adapter object map using a wrench adapter example

Bridge (bridge)

The bridge mode separates the abstraction section to its implementation, so that they can change independently. An ordinary switch-controlled electric light, electric fan, etc. are examples of bridging. The purpose of the switch is to turn the device on or off. The actual switch can be a simple double-knife zipper switch, or a dimming switch.

Figure 7: Bridge object map using electronic switch example

Combination example

The combination mode combines the object into a tree structure to indicate the "partial - overall" hierarchy. Let the user consistently use a single object and a combination object. Although the example is abstract, the arithmetic expression is indeed a combination. The arithmetic expression includes operands, operators, and another operand. The number of operands can be numbers or another expression. In this way, 2 3 and (2 3) (4 * 6) are legal expressions.

Figure 8: Combination mode object map using an arithmetic expression example

Decoration (Decorator)

Decorative model dynamically add additional duties to an object. Whether there is a picture without a picture, it can be hung on the wall, but it usually has a picture, and it is actually a picture frame being hung on the wall. Before hanging on the wall, the painting can be blinded, put it into the box; this time the painting, the glass and picture frame form an object.

Figure 9: Example of Decorative Mode Object Chart Appearance (FACADE) with a picture with picture frame

The appearance mode defines a unified higher level interface for interfaces in the subsystem for use. When the consumer is procured according to the directory, it reflects an appearance mode. Consumers have dial a number and customer service representative, and the customer service representative played this "look". He contains the interface with the order department, the cash register and the delivery department.

Figure 10: Appearance mode object map using the phone order example

Examples of Flyweight

Enjoying Yuan Mode Use sharing technology to effectively support a lot of fine-grained objects. The public switched telephone network (PSTN) is an example of enjoying the yuan. There are some resources such as dialing generators, ringing generators, and dial receivers that must be shared by all users. When a user picks up the handset, he doesn't need to know how much resources have been used. For users, all things are dial tones, call the number, and call the phone.

Figure 11: Enjoyment element mode object map using dial tone generator example

Proxy mode

Agent mode provides an intermediary to control access to this object. A check or bank deposit is a proxy for funds in the account. The check is used in market transactions in place of cash and provides control over the funds on the issuer.

Figure 12: Agent mode object map using the bank deposit case example

The next article will continue

Explore software design mode (2) "

UMLCHINA "

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

New Post(0)