4 years ago read "Big talk design mode" excerpt of the classic statement

Source: Internet
Author: User
Tags shallow copy

Objective

When looking for memcached related data in your own network, I stumbled upon the classic statement that I had read when I was reading "Big Talk design Mode" earlier. After reading this book, the design pattern has a superficial understanding, communicate with others can also say one or two. Thanks to the author for his selfless sharing!

Classic statement

1 reduced coupling of programs by encapsulation, inheritance, polymorphism
2 design mode makes the program more flexible, easy to modify, and easy to reuse
3 aggregation represents a weak ' owning ' relationship, which reflects that a object can contain a B object, but a B object is not part of a object [DPE]
4 Synthesis (composition, also translated into ' combination ') is a strong ' own ' relationship that embodies the strict part-to-whole relationship, part and whole life cycle [DPE]
5 programming is a technology, more an art
6 object-oriented programming, not the more classes the better, the class is divided for encapsulation, but the basis of classification is abstract, the abstract collection of objects with the same properties and functions is the class
7 Policy mode: It defines the algorithm family, respectively encapsulated, so that they can replace each other, this mode allows the algorithm changes, will not affect the use of the algorithm of the customer. [DP]
8 The strategy pattern is a method of defining a series of algorithms, conceptually, all of these algorithms do the same work, but the implementation is different, it can call all the algorithms in the same way, reducing the coupling between the various algorithm classes and using the algorithm class [DPE]
The advantage of the 9 policy model is that unit testing is simplified because each algorithm has its own class that can be tested individually on its own interface [DPE]
10 when different behaviors are stacked in a class, it is difficult to avoid using conditional statements to choose the appropriate behavior. Encapsulate these behaviors in separate strategy classes to eliminate conditional statements in classes that use these behaviors [DP]
The 11 policy pattern is used to encapsulate the algorithm, but in practice we find that it can be used to encapsulate almost any type of rule, as long as you hear the need to apply different business rules at different times during analysis, consider the possibility of using a policy pattern to handle this change [DPE]
12 in the basic policy mode, select the specific implementation responsibility that is assumed by the client object and transferred to the context object in the policy mode [DPE]
13 changes to any requirement are cost-
14 single duty principle, in the case of a class, there should be only one cause for it to change [ASD]
15 If a class takes on too much responsibility, it is tantamount to coupling these responsibilities, and a change in responsibility may weaken or inhibit the ability of the class to perform other duties. This coupling leads to a fragile design that will suffer unexpected damage when the change occurs [ASD]
16 Software Design a lot of what really needs to be done is to discover responsibilities and separate those responsibilities from each other [ASD]
17 If you can think of more than one motive to change a class, then this class has a redundant responsibility [ASD]
18 The open-close principle is that software entities (classes, modules, functions, etc.) should be extensible, but not modifiable. Open for extensions, closed for changes [ASD]
19 No matter how close the module is, there will be some changes that cannot be closed to it. Since it is impossible to be completely closed, the designer must choose which of the modules he designed should be closed. He must first guess what kinds of changes are most likely to occur and then construct abstractions to isolate those changes [ASD]
20 wait for immediate action when the change occurs [ASD]
21 when we first wrote the code, we assumed that the change would not happen. When changes occur, we create abstractions to isolate similar changes that occur in the future [ASD]
22 in the face of demand, changes to the program are made by adding new code, rather than changing the existing code [ASD]
23 We hope that the changes that may occur will be known soon after the development process is launched. The longer it takes to identify possible changes, the more difficult it is to create the correct abstraction [ASD]
24 open-close principle is the core of object-oriented design. Following this principle leads to the huge benefits claimed by object-oriented technology, which is maintainable, extensible, reusable, and flexible. Developers should abstract only those parts of the program that are showing frequent changes, but it is also not a good idea to deliberately abstract every part of the application, rejecting immature abstractions as important as the abstraction itself [ASD]
25 depending on the reversal principle, high-level modules should not rely on low-layer modules. Two should all rely on abstraction. Abstraction should not depend on detail. Detail should be dependent on abstraction. [ASD]
26 Richter Substitution principle, a software entity if you are using a parent class, you must apply its subclass, and it does not recognize the difference between the parent object and the child class object. That is, in the software, the parent is replaced by its subclasses, the behavior of the program does not change, in short, subtypes must be able to replace their parent type [ASD]
27 only if the subclass can replace the parent class, the function of the Software unit is not affected, the parent class is actually reused, and the subclass can add new behavior based on the parent class.
28 The substitution of subtypes makes it possible to extend a module that uses a parent class type without modification.
29 dependency reversal can be said to be the object-oriented design of the logo, in which language to write the program is not important, if the writing is to consider how to focus on abstract programming rather than the details of programming, that the program all the dependencies are terminated in the abstract class or interface, that is the object-oriented design, The reverse is the design of the process. [ASD]
30 decoration Mode (Decorator), to dynamically add some additional responsibilities to an object, the adornment mode is more flexible than the generation of subclasses for added functionality. [DP]
component is the definition of an object interface that can dynamically add responsibilities to these objects. Concretecomponent is to define a specific object, or to add some responsibility to the object. Decorator, decorate abstract class, inherit component, extend the function of component class from outer class, but for component, there is no need to know the existence of Decorator. As for the concretedecorator is the specific decorative objects, play to the component to add responsibility functions. [DPE]
32 Decorating mode is the use of setcomponent to wrap objects. In this way, the implementation of each adornment object and how to use this object separated, each adornment object only cares about its own function, does not need to care about any is added to the object chain. [DPE]
33 If there is only one concretecomponent class and no abstract component class, then the decorator class can be a subclass of Concretecomponent. Similarly, if there is only one Concretedecorator class, then there is no need to create a separate Drcorator class, and you can combine the responsibilities of decorator and Concretedecorator into a single class.
34 Decorating mode is a way to dynamically add more functionality to an existing feature.
35 The advantages of decorative mode, the decoration function in the class removed from the class, so that the original class can be simplified. Effectively separates the core responsibilities of the class from the decorative functional areas. It can also remove repetitive decorative logic from related classes.
36 proxy mode, which provides a proxy for other objects to control access to this object. [DP]
37 Types of proxy modes:
First, the remote agent, which is to provide local representation for an object in different address spaces. This can hide the fact that an object exists in a different address space. [DP]
Second, virtual proxies create expensive objects as needed. It is the real object that takes a long time to store the instantiation. [DP]
Third, the security agent, used to control the real object access permissions. [DP]
The intelligent guideline is that when the real object is called, the agent handles something else. [DP]
The biggest advantage of the 38 simple factory model is that the factory class contains the necessary logical judgments, dynamically instantiating the relevant classes based on the client's selection criteria, and for the client, to remove the reliance on the specific product.
39 Factory Method Mode (Factory), defines an interface that creates an object, letting subclasses decide which class to instantiate. The factory method defers the instantiation of a class to its subclasses. [DP]
40 when the factory method is implemented, the client needs to decide which factory to instantiate to implement the Operation class, and the problem of choice judgment is still there, that is, the factory method moves the internal logic judgment of the simple factory to the client code. You want to add the function, originally changed the factory class, and now is to modify the client!
41 prototype mode (PROTOTYPE), specifying the kind of objects created with the prototype instance, and creating new objects by copying the prototypes. [DP]
42 prototype mode is actually the creation of another customizable object from one object without the need to know the details of any creation.
431 like cloning is the best way to initialize information without changing it. This hides the details of object creation and greatly improves performance.
44 shallow copy, all variables of the copied object contain the same value as the original object. All references to other objects still point to the original object. Deep copy points The variable that references the object to the new object that was copied, rather than the original referenced object.
45 Since the inheritance is used, and it is certain that the inheritance is meaningful, it should be the template of the subclass, and all the duplicated code should go up to the parent class instead of having each subclass repeat.
46 When we are going to complete a process or a series of steps that are consistent at a certain level of detail, but the implementation of individual steps at a more detailed level may not be the same, we usually consider using the template method pattern to handle it.
47 Template Method mode, which defines the skeleton of an algorithm in an operation, and delays some steps into subclasses. The template method allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm. [DP]
The 48 template method pattern is the advantage of removing duplicate code from subclasses by moving the invariant behavior to the superclass.
49 Template Method mode is a great way to provide a good code reuse platform.
50 when immutable and mutable behaviors are mixed together in a subclass implementation of a method, the invariant behavior recurs in the subclass. We use the template method pattern to move these behaviors to a single place, thus helping the subclass to get rid of the repetition of the invariant behavior of entanglement.
51 Dimitri Law (LoD), if two classes do not have to communicate directly with each other, then these two classes should not have a direct interaction. If one of the classes needs to invoke a method of another class, the call can be forwarded through a third party. [J&DP]
52 in the structure design of a class, each class should minimize the access rights of members. [J&DP]
53 Dimitri The fundamental idea of the law is to emphasize the loose coupling between classes.
The weaker the coupling between the 54 classes, the more beneficial it is to reuse, and a class that is weakly coupled is modified without affecting the related classes.
55 appearance Mode (facade) provides a consistent interface for a set of interfaces in a subsystem that defines a high-level interface that makes this subsystem easier to use. [DP]
56 first, in the initial stage of the design, should be aware of the different two layers of separation, layer and layer to establish the appearance of facade; second, in the development phase, subsystems tend to become more and more complex due to the evolution of continuous refactoring, increasing the appearance of facade can provide a simple interface, reduce their dependence Thirdly, when maintaining a legacy large system, it is possible that this system is already very difficult to maintain and extend, and you can develop an appearance facade class for the new system to provide a clear and simple interface for designing coarse or highly complex legacy code, and to allow the new system to interact with the facade object. Facade interacts with legacy code for all complex work. [R2P]
57 If you need to separate the construction of a complex object from its representation, so that the same build process can create different representations of intent. We need to apply a design pattern, ' builder mode, also known as generator mode. If we use the builder model, then the user can just specify the type that needs to be built to get them, and the concrete construction process and details don't need to know.
58 Builder mode, which separates the construction of a complex object from its representation, so that the same build process can create different representations. [DP]
59 is primarily used to create complex objects in which the built-in order of the internal builds is usually stable, but the construction of the objects within the object often faces complex changes.
The 60 builder pattern is the one that applies when the algorithm that creates the complex object should be independent of the part of the object and how they are assembled.
The 61 observer pattern defines a one-to-many dependency that allows multiple observer objects to listen to a Subject object at the same time. This subject object notifies all observer objects when the state changes, enabling them to automatically update themselves. [DP]
62 a bad side effect of splitting a system into a series of collaborative classes is the need to maintain consistency among related objects. We do not want to be tightly coupled in order to maintain consistency, which can cause inconvenience to maintenance, expansion, and reuse. [DP]
The work done by the 63 observer pattern is actually decoupling. Let both sides of the coupling rely on abstraction, rather than relying on specifics. So that their changes will not affect the other side of the change.
A 64 delegate is a type of reference method. Once a delegate has been assigned a method, the delegate will have exactly the same behavior as the method. The use of a delegate method can be like any other method, with parameters and return values. A delegate can be thought of as an abstraction of a function, a function's ' class ', and an instance of a delegate representing a specific function.
65 all methods carried by the delegate object must have the same prototype and form, that is, have the same parameter list and return value type.
The 66 abstract Factory mode (abstract Factory) provides an interface to create a series of related or interdependent objects without specifying their specific classes. [DP]
67 programming is a gate art, such a large batch of changes, is obviously very ugly practice.
681 programmers If you have never stayed up late to write a program, it is not a good programmer, because he has not been obsessed, so he will not have great achievements.
69 state mode, when an object's internal state changes to allow its behavior to change, the object looks like it has changed its class. [DP]
70 state mode The main solution is when the conditional expression that controls an object state transition is too complex. It is possible to simplify the complex judgment logic by transferring the judgment logic of the state to a series of classes representing different states.
71 The behavior associated with a particular state is localized and the behavior of the different states is separated. [DP]
72 putting a particular state-related behavior into an object, because all state-related code exists in a specific state class, it is easy to add new states and transformations by defining new subclasses. [DP]
73 state mode reduces the dependency between the various state transitions by distributing the logic of the States to the subclasses of the state. When an object's behavior depends on its state, and it must change its behavior based on state at run time, you can consider using state mode.
74 Adapter Mode (Adapter), which transforms the interface of a class into another interface that the customer wants. The adapter mode makes it possible for those classes that would otherwise not work together because of incompatible interfaces to work together. [DP]
The system's data and behavior are correct, but the interface does not match, we should consider using the adapter, the purpose is to control the scope of an existing object and an interface matching. The adapter pattern is primarily used in situations where you want to reuse some existing classes, but the interfaces are inconsistent with the reuse environment requirements.
75 use an already existing class, but if its interface, that is, its methods and your requirements are not the same, you should consider using the adapter mode.
76 if the interface of different problems can be prevented in advance, the mismatch problem will not occur, when there is a small interface is not unified problem occurs, the timely reconstruction, the problem does not expand; only when it is impossible to change the original design and code of the situation, consider the adaptation. Afterwards control is inferior to the control, the control in the matter cannot control beforehand.
77 Memo (Memento): captures the internal state of an object without compromising encapsulation, and saves the state outside that object. The object can then be restored to its previously saved state. [DP]
78 the details to be saved are encapsulated in the memento, and the day you change the details of the save does not affect the client.
The memento model comparison is useful for classes that have complex functions, but need to maintain or record attribute history, or if a property needs to be saved is only a small part of a number of properties.
80 Command mode uses memo mode to store the state of an undoable operation if command mode is used in a system and the undo function of the command is required. [DP]
81 use memos to mask complex objects ' internal information to other objects. [DP]
When the status of a character changes, it is possible that the state is not valid, and you can use a temporarily stored memo to restore the state. [DP]
82 Memo mode is also flawed, the role state needs to be fully stored in the memo object, if the state data is much larger, then on the resource consumption, the memo object will be very memory-consuming.
83 combined Mode (Composite), which combines objects into a tree structure to represent the ' part-whole ' hierarchy. The combined mode makes the user consistent with the use of individual objects and composite objects. [DP]
84 when you find that a requirement is a structure that embodies a part and a whole hierarchy, and you want users to be able to ignore the difference between a combined object and a single object, you should consider combining patterns when you use all the objects in a composite structure uniformly.
The 85 iterator pattern (Iterator) provides a way to sequentially access individual elements in an aggregated object without exposing the object's internal representation. [DP]
86 when you need to access a clustered object, and no matter what these objects need to traverse, you should consider using the iterator pattern. When you need to iterate over the aggregation in several ways, you can consider using an iterator pattern. Provides a unified interface for traversing different aggregation structures, such as start, next, end, current, and so on.
The 87 iterator (Iterator) pattern separates the traversal behavior of the collection object, abstracting an iterator class to be responsible for not exposing the internal structure of the collection, but also allowing the external code to transparently access the data inside the collection.
88 Singleton Mode (Singleton), which guarantees that a class has only one instance, and provides a global access point to access it. [DP]
89 usually we can have a global variable that makes an object accessible, but it doesn't prevent you from instantiating multiple objects. One of the best ways is to have the class itself responsible for preserving its only instance. This class guarantees that no other instance can be created, and it can provide a way to access the instance. [DP]
The lock is to ensure that when one thread is in the critical section of the code, the other thread does not enter the critical section. If another thread attempts to enter the locked code, it waits (that is, is blocked) until the object is freed.
91 The static initialization method is to instantiate itself when it is loaded, so it is called the A Hungry man-type singleton class, so it is called as a lazy singleton class to be instantiated for the first time. [J&DP]
92 the inheritance of an object is defined at compile time, so the implementation inherited from the parent class cannot be changed at run time. The implementation of the subclass has a very close dependency on its parent class, so that any changes in the parent class implementation will inevitably cause the subclass to change. When you need to reuse a subclass, the parent must override or be replaced by another more appropriate class if the inherited implementation is not appropriate to solve the new problem. This dependency limits flexibility and ultimately limits reusability. [DP]
Synthetic/Aggregation multiplexing principle (CARP), use composition/aggregation as much as possible, and do not use class inheritance as much as possible. [J&DP]
93 aggregation represents a weak ' owning ' relationship, which shows that a object can contain a B object, but that the B object is not part of a object; the composition is a strong ' own ' relationship, embodying a strict part-to-whole relationship, part and whole life cycle. [DPE]
94 prioritizing the composition/aggregation of objects will help you keep each class encapsulated and focused on a single task. Such class and class inheritance hierarchies remain small and are unlikely to grow into uncontrollable behemoths. [DP]
95 Bridging Mode (bridge), separating the abstract part from its implementation, so that they can vary independently. [DP]
What is called abstraction is separate from its implementation, which is not to say that the abstract class is separated from its derived class because it makes no sense. An implementation refers to an abstract class and its derived classes that are used to implement their own objects. [DPE]
96 The implementation system may have multi-angle classification, each classification is likely to change, then the multi-angle separation to allow them to change independently, reducing the coupling between them.
97 Command mode, which encapsulates a request as an object, allowing you to parameterize the customer with different requests, queue up requests or log requests, and support undoable operations. [DP]
The role of the command mode: 1 It is easier to design a command queue, 2 it can be easier to log the command in case of need, 3 allows the party receiving the request to decide whether to veto the request, 4 can easily implement the undo and redo of the request, 5 because the addition of the new specific command class does not affect other classes, So it is easy to add new specific command classes; The 6 command mode splits the object that requests an action with the object that knows how to perform an operation. [DP]
98 Agile Development Principles tell us not to add guessing-based, actually unwanted features to your code. If you do not know whether a system requires command mode, generally do not rush to implement it, in fact, it is not difficult to implement this mode when needed by refactoring, only in the real need such as undo/redo operations and other functions, the original code refactoring into a command mode is meaningful. [R2P]
99 Responsibility Chain mode (Chain of Responsibility): Enables multiple objects to have the opportunity to process requests, thus avoiding the coupling between the sender and receiver of the request. Link the object to a chain and pass the request along the chain until an object handles it. [DP]
100 when a customer submits a request, the request is passed along the chain until a Concretehandler object is responsible for processing it. [DP]
101 Neither the recipient nor the sender has a clear message of the other, and the object in the chain does not know the structure of the chain. The result is that the chain of responsibilities simplifies the connection of objects, and they only need to maintain a reference to the successor, without having to keep all of its candidate recipients ' references. [DP]
102 Add or modify the structure to process a request at any time. Increased flexibility in assigning responsibilities to objects. [DP]
102 Mediator Mode (mediator), which encapsulates a series of object interactions with a mediation object. The mediator makes the objects not need to be referenced to each other, so that they are loosely coupled and can independently change the interaction between them. [DP]
The 103 broker mode is easy to apply in the system and is easily misused in the system. When the system appears ' many-to-many ' interacting complex object groups, do not rush to use the intermediary mode, but first to reflect on the design of your system is not reasonable.
The advent of the 104 mediator reduces the coupling of the various colleague, allowing individual colleague classes and mediator to be independently changed and reused, as an abstraction of how objects work together, and mediations as an independent concept and encapsulated in an object. The object of such attention is shifted from the behavior of the objects themselves to the interaction between them, that is, to stand in a more macroscopic view of the system.
The 105 terminator pattern is typically applied to a set of objects in a well-defined but complex way to communicate, and to customize a behavior that is distributed across multiple classes without having to generate too many subclasses.
106 enjoy meta mode (Flyweight), application sharing technology effectively supports a large number of fine-grained objects. [DP]
The 107 enjoy meta-mode avoids the overhead of a large number of very similar classes. In programming, it is sometimes necessary to generate a large number of fine-grained class instances to represent the data. If you can see that these instances are essentially the same except for a few parameters, you can sometimes be greatly reduced the number of classes that need to be instantiated. If you can move those parameters outside of the class instance and pass them in when the method calls, you can drastically reduce the number of individual instances by sharing.
108 If an application uses a large number of objects, and a large number of these objects cause a lot of storage overhead should be considered, and that is the majority of the state of the object can be external state, if you delete the external state of the object, you can use a relatively small number of shared objects to replace many groups of objects, Consider using the enjoy meta mode at this point.
109 interpreter mode (interpreter), given a language, defines a representation of its grammar and defines an interpreter that uses that representation to interpret sentences in the language. [DP]
110 If a particular type of problem occurs at a sufficiently high frequency, it may be worthwhile to describe each instance of the problem as a sentence in a simple language. This allows you to build an interpreter that solves the problem by interpreting these sentences. [DP]
111 You can use the interpreter pattern when there is a language that needs to be interpreted and executed, and you can represent a sentence in that language as an abstract syntax tree. [DP]
112 easily change and extend the grammar, because the pattern uses classes to represent grammar rules, and you can use inheritance to change or extend the grammar. It is also easier to implement grammars because the classes that define the individual nodes in the abstract syntax tree are broadly similar in their implementation, and are easy to write directly. [DP]
113 There is also a shortage of interpreter patterns, and the interpreter pattern defines at least one class for each rule in the grammar, so grammars that contain many rules can be difficult to manage and maintain. It is recommended to use other techniques, such as a parser or compiler builder, when the grammar is very complex. [DP]
114 Visitor Mode (Visitor), which represents an action that acts on elements in an object's structure. It allows you to define new actions that act on these elements without changing the class of each element. [DP]
The 115 visitor pattern is suitable for systems with relatively stable data structures, which frees up the coupling between the structure and the operation of the structure, allowing the set of operations to evolve relatively freely.
116 The purpose of the visitor pattern is to separate the processing from the data structure. With a more stable data structure and easy-to-change algorithms, it is more appropriate to use the visitor pattern because the visitor pattern makes it easier to increase the algorithm's operation.
The advantage of the 117 visitor pattern is that it is easy to add new operations because adding new operations means adding a new visitor. The visitor pattern concentrates the behavior on a visitor object. The disadvantage of the visitor is that it becomes difficult to add new data structures.

Postscript

Thank the author again!

4 years ago read "Big talk design mode" excerpt of the classic statement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.