Software systems in software, a modular design of the main well, the most important sign is that the module will be the extent to which its own internal data and other details of the realization of the hidden. Well a well-designed module can achieve all of its hidden details, will be made available to complete the API and the outside world to achieve their own separate. As a result, between the module and the module can be only through each other's API to communicate with each other, irrespective of the details of the work within the module.
OO design are the guiding principles is to improve the maintainability and reusability. These principles are:
1. <br /> The principle of open and close a software entity expansion should be open, closed for modification.
In the design of a module when the module on when to make the modifications can not be extended under the premise. In other words, we would be able to modify the source code do not have to change the behavior of this module.
How not to amend, but also can be extended?
To solve the problem lies in the abstract: In the Languages can be given one or more abstract Java class or interface, all the provisions of the specific type of method must be provided as system design characteristics of the abstraction layer. This abstraction layer foresee all the possible expansion, therefore, in any case, the expansion will not change. This makes the system abstraction layer does not need modification to meet the needs of the - to amend the closure.
At the same time, abstraction layer derived from one or more specific types of new systems can change the behavior, so the design of the system is open to expansion.
The principle of opening and closing is the "closure of the principle of variability": to find a system of variable factors, will be packaged together. This principle means that two points:
1) a variability in the code should not be scattered in many corners, and should be packaged inside an object. With a different appearance of variability means that the succession of the same hierarchical structure of the specific subclass.
When the succession to be seen as a change in method of packaging and should not be considered the object from the general method to generate a special object.
2) a variable with another should not be mixed with variability. (All types of succession plans in general no more than a two-tier structure, or means that the variability of two different mixed together.)
The principle of opening and closing general principle, other principles of a few is a means of opening and closing and tools.
2. To rely on the principle of reverse <br /> stresses the principle of relying on reverse is: To rely on the abstract, do not trust to achieve.
The principle of opening and closing is the goal, but a means to achieve this goal is dependent on the reverse principle.
Level of abstraction is the application that contains business logic and the macro of the whole system is an important strategic decision is a manifestation of inevitability; and concrete level contains a number of minor and implementation of the algorithms and logic, as well as tactical decision, with a considerable chance to choose. Specific code-level changes will be frequent and can not avoid an error.
Abstract level of an application containing the most important macro-system business logic, so the strategy is to judge and decide on a place, then on the level of abstraction should be relatively stable, should be the focus of reuse; also to maintain the focus should be.
In many cases, a Java program requires a reference to an object. This time, if the object has an abstract type of case, should the use of the abstract type as a static type of variable. This is the meaning of programming for the interface.
Generally speaking, when in the creation of an object, Java language requires the use of new words as well as the category itself. Once this object has been created, it can be flexibility in the use of the abstract type of object it is invoked. For example: List employees = new Vector (); Therefore, Java language in the process of creating an object is contrary to the "open closed principle" and the reliance on the principle of reverse (because the President has become a specific type, then the use of abstract reference), although This class was created after the polymorphism can be made through the client-side dependence on its abstract type. It is because of this problem, given a number of design patterns to create models, in particular, a number of plant model, the object used to create a reversal in the process of problem-dependent.
Factory pattern to create a class example of the process of packaging, and consumption in this case the client is only an example of the results obtained, as well as the examples of the abstract type. Of course, any method can not avoid the requirements of Java language keywords and direct calls new concrete sub-structure approach (which goes against the principle of substitution Richter). Simple factory pattern to the violations of "the principle of open and close" and rely on the reverse principle to a type of packaging it, and the factory method in violation of the principle of this mode of practice to defer to the specific role of the factory. Through appropriate packaging, factory pattern can purify most of the structure, but the practice would violate the principle of isolation to a place easier to control.
Joint use of Java interfaces and Java abstract class: statement type of commitment by the Java interface, but at the same time given a Java abstract class for this interface is given the realization of a default. If a specific type of direct realization of the Java interface, then it must own all of the interface; the other hand, if it is inherited from the abstract class, then, it eliminated some unnecessary because it can automatically from the abstract class to be the realization of these methods by default. In fact, this is the default mode of adaptation.
The shortcomings of relying on reverse:
1) upside down, having to depend on the reason, the object is likely to create a factory object to use in order to avoid direct reference to specific categories, the use of this principle will lead to a large number of categories. On object-oriented technology are not familiar with the engineers, the maintenance of such a system requires a good knowledge of object-oriented design.
2) reverse the principle of relying on the assumption that all of the specific types of change are, and this is not always correct. There are a number of specific categories can be quite stable, will not change, consumption of this specific instance of a class that the client can be dependent on the specific types, rather than an abstract type for this invention.
3. Where's the principle of substitution <br /> base class can occur in any place, there will certainly be able to subclass.
The principle of opening and closing the key step is to abstract. The base class and subclass of the inheritance is the concrete embodiment of abstract, Richter substitution principle is the realization of abstract norms of concrete steps.
4. Synthesis / polymer complex principles
To make full use of synthesis / polymerization, rather than inheritance to achieve the purpose of reuse.
Synthesis / polymerization of the principle requires that we first consider the synthesis / polymerization of the relationship between Richter substitution principle requires the use of inheritance, it is important to determine the relationship between the succession meet certain conditions (the succession of changes is used to package; no base class can have a place , sub-categories will be able to appear.)
Synthesis / polymerization is the principle of a new object inside the object has been to use to become part of a new object; new object through the assignment to achieve these objects may have functional reuse purposes.
5. Dimitr <br /> principle a software entity should be as little as possible interaction of other entities. Interaction between modules less. The result is the need to expand the function of the system will be relatively easier to achieve the closure of the amendment.
An object to other objects should be as small as possible to understand.
Dmitry is the principle of specific steps:
1) give priority consideration to set up a class into the same category. The same type of easy to design, implementation and use. For example, Java API in the String, BigInteger, etc. category.
An object of communication with the outside world in general divided into two, one is to change the status of this object, and the other is not to change the state of the object. If the internal state of an object simply can not be changed, then it's communication with the outside world of course, greatly reduced.
When involved in any type of time, are the first state to consider whether this type needs to change. Even if a class must be a variable type, in the property to its assignment method, we must maintain a mean attitude. Unless really necessary, or not as a property assignment method.
2) to minimize the cost of access to a class.
3) be used with caution Serializable, once set up a class Serializable, the new version can no longer modify the internal structure of this class, including private ways and sentence paragraph.
4) to minimize access to the members.
6. <br /> Interface segregation principle should be as small as possible the client to provide a separate interface, and not provide the total interface. That is, the use of multiple specialized interface than using a single interface is better overall.
Interface segregation principle and Dmitry are a software entity with other entities of the communication software restrictions. Dmitry principle as far as possible to limit the breadth and depth of communication, then the principle of segregation requirements Commodities Communication narrow width as much as possible. As a result of a software system in the functional expansion process, the pressure will not modify the object passed to the other.
The equivalent of an interface plays a role in, and this role in a stage to which an actor is the equivalent of speech interface. Therefore, an interface should be simple to represent a role, rather than multiple roles. If the system involves a number of roles, then the role of each should be carried out by the representative of a specific interface.
Custom Service: If the client only needs a certain number of methods, then the client should be provided to those needs, rather than the method does not need to provide. (Provided to the client interface is a public commitment, there is no need to make a commitment to unnecessary, excessive commitment to the maintenance of the system will be an unnecessary burden.)
///////////////////
Design patterns in java there are several important design principles:
1, Lane's substitution principle (LSP)
Richter strict expression of the principle of substitution is:
If the T1 of each type of object O1, have T2 object of type O2, makes the definition of T1 in all the procedures of the object P in all O1 were replaced by O2, the procedure does not change behavior of P, then type T2 is a subtype of the type of T1.
2, rely on the reverse principle (DIP)
Dependent on the formulation of the principle is reversed:
Abstract should not be dependent on the details; details should depend on the abstract. (Abstractions should not depend upon details. Details should depend upon abstractions). Another of his statements is: If the interface for programming, not for the realization of program (Program to an interface, not an implement-action)
3, interface segregation principle (ISP)
The use of a number of specialized interface than using a single interface is better overall.
4, synthesis / polymerization of the principle of multiplexing (CARP)
Into / aggregation principle, which is reusable in a new object inside the object has been to use to become part of the new object; new object to the appointment of these objects have been used to achieve functional rehabilitation purposes.
This principle there is another table book: To make full use of synthesis / polymerization, as far as possible not to use inheritance
5, Dmitry law (LOD)
Book table of many!
////////////////////////////
Java design principles <script> </ script>
1. First of all, clear communication between objects, there are two ways, one is the implicit one is explicit, the so-called explicit, that is, point-to-point communications, the so-called implicit, that is, broadcasting, playing months for example, teachers ask students, said: Xiao-ming up to answer questions, ok, this is prescribed by the teacher and small display communications, said the teacher: to answer questions which the students, OK, this is implicit between teacher and student communication.
2. The principles of clear communication, we also need to know that explicit and implicit characteristics of both what, ok, is the explicit one-on-one, high efficiency, but the communication of a fixed object, is not flexible enough, hidden Although the efficiency of type significantly low, but the high degree of flexibility.
3. To understand the above situation, we can carry out specific design, in general, an application can be layered
Show style
Function details
Workflow
Organizational structure
Data structures and algorithms
Bottom-up, more easy to change, so to use significantly more low-level communication, improve efficiency, high-level to use implicit communication, increased flexibility to adapt to change. With such demand, at the top, in fact, is the type of design, at the bottom is the data structure and algorithm design, data structures and algorithms on the basis of the design category by the accumulation of experience, but we can still find some type of design law
4. OCP followed the principle that the code to increase, can not be changed, according to our teacher said so, the code is broken, not bad writing is changing for the worse, and I am sure many people have this feeling, I also feel a deep, Therefore, in the old system extensions or other needs should be added the code as far as possible, rather than modify the source code.
5. To understand the relationship between categories is also very important, in general there are five kinds of class relations, dependence on <link <Aggregation <portfolio <inheritance
That they are less than its coupling degree of contrast, here, it is necessary to clear the relationship between dependence is a kind of method parameters, used in another class, or method to generate another type of object, which is temporary object, so that the two types of dependent relationship; related concept of the 1 to 1,1, and many-to-many relationship, such as a teacher more than students, but teachers should not be a collection of students as an attribute, that is to say they are 1 relationship and more; polymerization is owned include semantics, objects are loose, some may be more than the whole, you can create a distribution; portfolio is a part of the whole object can only belong to one object, not a whole not a part of the natural
6. To understand these relationships in your Class UML design is very useful in the design category, priority is given to polymer, and then consider the inheritance, succession of the most multi-storey should not be more than three layers, including the 3-layer, all types of design, are to a goal, that is, changes in package! Therefore, object-oriented programming that is oriented programming interface, always in the design of the time, do not think the realization, that is 23 kinds of the origin of the design mode, if the attention will find that 23 kinds of design patterns that are is based on the abstract class and interface, and this is for the interface, do not care about the achievement of concrete, will be deferred to the subclass, package changes, so that business logic with the change, convenient to reach the deep-level object-oriented design, Beginners may think that why should we design pattern, why should the less complex, in fact, the experience you need to feel real, not forced to understand their own, and you will understand the natural, but failed to go through on such as I project, the first is perfect, but the demand for change, I found a good pain program, not the design of how the pain ah! Ha ha we look at design patterns, ah with emotion.







