****** Design mode: Mini manual ****** (more pictures, please patiently)

zhaozj2021-02-08  209

TD {background-color: whitesmoke;}

Create structure type behavior type based Factory Method Adapter_Class InterpreterTemplate Method objects Abstract FactoryBuilderPrototypeSingleton Adapter_ObjectBridgeCompositeDecoratorFacadeFlyweightProxy Chain of ResponsibilityCommandIteratorMediatorMementoObserverStateStrategyVisitor Overview

Name The Factory Method structure is integrated to define an interface for creating an object, allowing subclasses to instantize which class. Factory Method delays a class of instantiation to their subclasses. applicability

When a class does not know the class of the object it must create. When a class wants to specify the object it created by its subclass. When classes will create a responsibility of the object to a multiple help subclass, and which helper subclass will be the agent of the agent.

Name The Abstract Factory structure intent provides an interface to create a series of associated or interdependent objects without specifying their specific classes. applicability

A system is to be independent of its product creation, combination, and representation. A system is to be configured by one of a plurality of product lines. When you want to emphasize a series of related product objects for union use. When you provide a product class, just want to display their interfaces instead of implementation.

Name The builder structure is integrated to separate a complex object to its representation, so that the same build process can create different representations. applicability

When creating a complex object, the algorithm of complex objects should be independent of the component of the object and their assembly methods. When the constructor must allow the object to be constructed to have different representations.

Name The prototype structure intended to specify the type of object to create an object with a prototype instance, and create a new object by copying these prototypes. applicability

When the class to be instantiated is specified at runtime, for example, by dynamic loading; or to avoid creating a factory class level parallel to the product class hierarchy; or when a class can only have several different status combinations One time. Establish a corresponding number of prototypes and clone them may be more convenient than manually modified each time you use a suitable state.

Name The Singleton structure intent ensures that only one instance is only one instance and provides a global access point access to it. applicability

When the class can only have one example and the customer can access it from a well-known access point. When this unique instance should be expandable by subclassization, and the customer should use an extension instance without changing the code.

Name Adapter Structure intention to convert a class interface into another interface that customers want. A D A P T E R Mode allows you to work with those classes that are not compatible without compatibility. applicability

You want to use an existing class, and its interface does not meet your needs. You want to create a class that can be multiplexed, which can work with other unrelated classes or unpredictable classes (ie those that may not be compatible with those interfaces). (Only for object a d a p t e r) You want to use some already existing subclasses, but it is impossible to make subcarcies for each one to match their interfaces. The object adapter can adapt its parent class interface.

The name Bridge structure is integrated to separate the abstraction section to its implementation, so that they can be independently changed. applicability

You don't want to have a fixed binding relationship between abstract and its implementation. For example, this may be because the part should be selected or switched at the program runtime. The abstraction of the class and its implementation should be expanded by the method of generating subclasses. At this time, B R I D GE mode allows you to combine different abstract interfaces and implementations and expand them separately. The modification of an abstract implementation should have no impact on the customer, that is, the customer's code does not have to recompile. (C ) You want to completely hide the abstract implementation part of the customer. In C , the class represents is visible in the class interface. There are many classes to be generated. Such a class hierarchy indicates that you must decompose an object into two parts. R u m b A u g h refers to this type of hierarchy as "Nested Generalization). You want to share implementations between multiple objects (possibly using reference counts), but at the same time as they don't know this. A simple example is the S t R I n g class [C O P 9 2] of C O P L I e n, and multiple objects in this class can share the same string representation (S T R I N G R E P). Name The Composite structure is intended to combine the object into a tree structure to indicate the "part - overall" hierarchy. C O m P O S I makes the user consistency for the use of a single object and a combined object. applicability

You want to indicate part of the object - the overall hierarchy. You want users to ignore different combined objects and individual objects, and users will unify all objects in the combined structure.

Name Decorator structure intentively adds some additional duties to an object. In terms of increased function, D e C O R A T O R is more flexible compared to generated subclasses. applicability

Add responsibility to a single object in a dynamic, transparent manner without affecting other objects. Handling those responsibilities that can withdraw. When the method of generating subclasses cannot be expanded. One case is that there may be a large number of independent extensions, to support each combination, which will generate a large number of subclasses, resulting in explosive growth. Another situation may be because class definitions are hidden, or class definitions cannot be used to generate a subclass.

Name The FACADE structure is intended to provide a consistent interface in a set of interfaces in the subsystem, and the F A C A D E mode defines a high-level interface, which makes this subsystem easier to use. applicability

When you want to provide a simple interface for a complex subsystem. Subsystems tend to become more complicated because of continuous evolution. Most mode uses more smaller classes. This makes the subsystem more reusability, and it is more easier to customize the subsystem, but this also brings some difficulties to those users who do not need to customize subsystems. F A C A D E provides a simple default view that is sufficient to most users, while those who need more customizable can cross the F A C A D e-layer. There is a lot of dependence between the client program and the abstract class. Introducing F A C A D E separates this subsystem to customers, and other subsystems, can increase the independence and portability of the subsystem. When you need to build a hierarchy subsystem, use the F A C A D E mode to define the entry point of each layer in the subsystem. If the subsystem is interdependent, you can make them communications only by F A C A D e, thereby simplifying the dependencies between them.

Name The Flyweight structure intention to use shared technology to effectively support a lot of fine-grained objects. applicability

An application uses a lot of objects. Due to the use of a large number of objects, large storage overhead is caused. Most of the objects can be variable to external state. If you delete an external state of an object, you can replace a lot of group objects with relatively few shared objects. The application does not depend on the object identity. Since the F L Y W E I G H T object can be shared, the identification test will return true value for the conceptual obvious object.

Name The Proxy structure is intended to provide a proxy for other objects to control access to this object. Applicability Use the P R O X Y mode when you need to use a relatively universal and complex object pointers instead of a simple pointer. Below is a common situation that can use P R O X Y mode: 1) Remote Proxy provides a local representative for an object in different address space. Nextstep [add94] implements this with the N x P R O X Y class. Coplien [COP92] said this agent is "Ambassador" (A M B A S S A D O R). 2) Virtual Proxy) Create a large number of overheads that are overhead as needed. The I m a g e p r o x y described in the motivation section is an example of a proxy. 3) Protection Proxy controls access to the original object. Protecting agent is used for objects that should have different access rights. For example, K E M E L P R O X I e s provides access protection for operating system objects in C HO I C e s operating system [C i r m 9 3]. 4) Smart Reference replaces a simple pointer that performs some additional operations when accessing objects. Its typical use includes counting the reference to the actual object, so when the object is not referenced, it can be automatically released (also known as S M A R TP O I N TER S [E D E 9 2]). When a persistent object is first referenced, it is loaded into memory. Check if it has been locked before accessing an actual object to make sure other objects cannot change it.

Name Chain of Responsibility structure intends to make multiple objects have the opportunity to process requests, thereby avoiding coupling relationships between requesting senders and recipients. Connect these objects into a chain and deliver the request along this chain until there is an object to process it. applicability

There are multiple objects to handle a request, which object handles the request running time automatically determines. You want to submit a request to a number of objects in a number of objects without clearly specifying the recipient. A collection of objects that can be handled should be dynamically specified.

Name Command Structure intention to package a request into an object, so that you can use different requests to parameterize the customer; queuing or logging the request log, and supports the revocable operation. applicability

As the M e N U I TEM object discussed above, the action to be performed is used as parameters. This parameterization mechanism can be expressed in the process language in the process language (C A L B A C K) function. The so-called callback function means that the function is registered at some place, and it will be called at a later need. The C O m m a n d is an object-oriented alternative to a callback mechanism. Specify, arrange, and execute requests at different times. A C O m M M m M M a N d may have a survival that is independent of the initial request. If a requested recipient can be expressed in a manner that is independent of address space, you can transfer the command object responsible for the request to another process and implement the request there. Support cancel operation. The e x C U t e operation of C O m M a N D can store status before implementing operations, which is used to eliminate the impact of the operation when the operation is canceled. The C O m M a N D interface must add an U N e x e c u t e operation, which cancels the effect of the last e x e c u t e called. The execution command is stored in a historical list. "Cancel" and "redance" and "re-do" can be achieved by calling the back and forward traversing of this list and call U n e x e c u t e and e x e c u t e. Support for modification logs so that these modifications can be renovated when the system crashes. Add load operations and storage operations in the C O m M A N D interface, which can be used to maintain a consistent modification log. The process recovered from the crash includes re-executing the recorded commands in the disk and re-executing them with the E x E C U t. Constructs a system with a high-level operation of the primitive operation. Such a structure is common in the information system that supports the transaction (T R a N S A C T I O N). A transaction packages a set of changes to the data. The C O m M a N d pattern provides a method of modeling a transaction. C O m m a n D has a public interface that allows you to call all transactions in the same way. It is also easy to add new transactions to expand the system. Name Interpreter Structure intention to give a language, define a representation of its textual law, and define an interpreter that uses this representation to explain the sentence in the language. applicability

When there is a language that needs to be explained, and you can use the sentence in the language as an abstract syntax tree, you can use the interpreter mode. When there is a case where there is a situation: This grammat is simple for complex grammar, and the class level of literacy has become huge and cannot be managed. Tools such as Syntax Analyzer Builders are better options. They can explain their expressions without building abstract syntax trees, which saves space and may save time. The efficiency is not a key problem. The most efficient interpreter is usually not implemented by direct interpretation of the syntax analysis tree, but first converts them into another form. For example, regular expressions are typically converted into a state machine. But even in this case, the converter can still be implemented by the interpreter mode, which is still useful.

Name The Iterator structure is intended to provide a method sequential to access each element in a polymeric object without exposing internal representation of the object. applicability

Accessing the content of a polymeric object without exposing the internal representation of it. Supports a variety of traversal to the polymer object. Provide a unified interface (ie, support polymorphism iteration) for traversing different aggregates.

Name Mediator Structure intends to encapsulate a series of object interactions with one intermediary object. The intermediaries make the objects need not be explicitly cited to each other, making them rolling, and can independently change the interaction between them. applicability

A set of objects communicate in a well-defined but complex manner. The resulting interdependent relationship structure is confusing and difficult to understand. An object refers to many other objects and communicates with these objects directly, causing difficult to reuse the object. Want to customize a behavior distributed in multiple classes, and don't want to generate too much subclasses.

Name The MEMENTO structure is intended to capture an internal state of an object without damaging the encapsulation, and save this status outside of the object. This will restore the object to the originally saved state. applicability

An object must be saved (partially in a certain time, so it can restore it to the previous state. If an interface is used to get other objects directly to these states, the implementation details of the object will be exposed and the encapsulation of the object is destroyed. Name OBServer Structure Integrated Defines a one-to-many dependency between objects, when the status of an object changes, all objects that depend on its object are notified and automatically updated. applicability

One aspects are dependent on the other aspect. The two are encapsulated in separate objects to make them independently change and reuse. When changes to an object requires simultaneous changes, don't know how many objects have to be changed. When an object must notify other objects, it can't assume who other objects are. In other words, you don't want these objects to be closely coupled.

Name The STATE structure is integrated to allow an object to change its behavior when its internal state changes. Objects seem to modify its class. applicability

The behavior of an object depends on its status, and it must change its behavior based on the state according to the state. One operation contains a huge multi-branch conditional statement, and these branches depend on the status of the object. This state is usually represented by one or more enumerations. Typically, there is a plurality of operations comprising this same conditional structure. The S t a t E mode puts each conditional branch into a separate class. This allows you to use the status of the object as an object based on the situation itself, which can independently depend on other objects.

Name The Strategy Structure is intended to define a series of algorithms, encapsulate them, and allow them to replace each other. This mode makes the algorithm can be varied independently of its customers. applicability

Many related classes are only different. "Policy" provides a method of configuring a class with a behavior in multiple behaviors. Different variants of an algorithm are needed. For example, you may define some algorithms that reflect different space / time weigh. When these variants are implemented as a class level of an algorithm [H O 8 7], policy mode can be used. The algorithm uses the data that customers should not know. The policy mode can be used to avoid exposure to complex, with the data structure related to the algorithm. A class defines a variety of behaviors, and these behaviors appear in the form of multiple conditional statements in this type of operation. External conditional branches into their respective S T R A T E G Y classes instead of these conditional statements.

Name The Template Method structure is intended to define the skeleton of an algorithm in an operation, and delay some steps into the subclass. TE M P L A T E M e T H O D can redefine certain specific steps of the algorithm without changing the structure of an algorithm. applicability

Distribute a constant portion of an algorithm in one time, and reforms the variable behavior to subclasses. Public behavior in each subclass should be extracted and concentrated into a public parent class to avoid code repeat. This is a good example of "heavy decomposition" described by O P D Y K E and J O H N S O N [O J 9 3]. First identify the differences in the existing code and separately separate from the new operation. Finally, these different code is replaced with a template method that calls these new operations. Control subclass extension. The template method only calls the "H O K" operation at a particular point (see the effect section), which allows only to expand these points.

Name The Visitor structure is intended to represent the operation of each element acting in a target structure. It allows you to define new operations for these elements without changing the class of each element. applicability

An object structure contains many types of objects, which have different interfaces, and you want to implement some operations that depend on their specific class. There is a need for many different and discontinued operations in an object structure, and you want to avoid these objects of these objects to "pollution". VI S i T O r makes you focus on a class in a class. When the object structure is shared by many applications, the VI S i T O R mode allows each application only contains the required operations. Define the class of the object structure rarely change, but often needs to define new operations on this structure. Changing the object structure The structure needs to redefine the interface to all visitors, which may require a lot. If the object structure class changes, it is possible to define these operations in these classes.

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

New Post(0)