Design mode can be used for object-oriented software base (1) - legend

xiaoxiao2021-03-05  30

Start learning design mode, from the online "design mode to be used for object-oriented software-oriented software", read the introduction, found that you have written so much self-righteous code, but use the idea of ​​design mode, all Is garbage! !

It seems to be charged. A journey of a thousand miles begins with a single step, first summarizes the illustration of the design pattern:

Legend: 1). Instantiate the broken arrow line in the figure below represents an object that instantizes another class, and the arrow points to the class of an instantiated object. 2). Inherit us indicate sub-relationships with vertical lines and triangles, as shown below. 3). The name of the abstract class abstract class is expressed in italics to distinguish between specific classes. Abstract operations are also represented by a bevel. The pseudo code that implements the operation is included. 4). Mixin Class mixed into a class that provides a class that provides an optional interface or functionality to other classes. It cannot be instantiated as abstract classes. Mixing requires multiple inheritance, illustrated below. 5). Delegation is a combination method that makes the combination have the same reuse capabilities as inheritance [LIE86, JZ91]. In the entrustment mode, there are two objects to participate in processing a request, and accept the requested object will be delegated to its agent (DELEGATE). This is similar to the parent class processing that the subclass will be delivered to it. When using inheritance, the inherited operation is always reference to the acceptable object, and C via the THIS member variable, in SmallTalk is passed by Self. In order to obtain the same effect, the entrustment method accepts the requested object to pass itself to the client (agent), enabling the object being entrusted, can reference the acceptable object. The arrow line represents a reference relationship between another class instance. The reference name is optional, this example is "Rectangle". 6). Aggregation and acquaintance polymerization means that one item has another object or is responsible for another object. Generally we call an object contains another object or part of another object. Aggregation means that the polymer object and its owner have the same lifecycle. Game means that an object only knows another object. Sometimes it is also known as "associated" or "reference" relationship. Accomplicated objects may request each other's operation, but they are not responsible for the other party. Accessibility is a relatively weak relationship, which only identifies more loose coupling relationships between objects. In the figure below, the ordinary arrow line represents each of them, and the tail has a diamond-shaped arrow line represents the polymer: C , the aggregation can be implemented by defining a member variable indicating the true instance, but more typically defines these member variables as instance pointers. Or references; each assignment is also implemented in a pointer or reference. Fundamentally, is aggregation or acquaintance is determined by your intent rather than by explicit language mechanism.

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

New Post(0)