<Just write> the basic principles of software design

1. The high cohesion, low coupling

  The so-called high cohesion, refers to a software module within the various elements combine with each other to close the high degree that a software module is a strong correlation between the composition of the code, is only responsible for one task, which is often said that the single responsibility principle.

  The so-called low coupling means the degree of interconnection between the different modules within a software system to be lower. The closer links between the different modules, coupling the stronger its independence module is worse, the coupling between modules depends on the level of complexity of interfaces between modules, way calling and transmission of information.

  Therefore, in a software system, should try to ensure the independence of the module, the module implements a single function duties, the simpler the better. This facilitates reuse system, and greatly reduce the dependence between the modules, system stability, easier to maintain.

2. abstract-oriented programming

  Process-oriented, component depends on the lower layer is too large, in case of changes, with changes required. Low reusability of software components modules, increasing the cost of software development and software architecture design bloated, is not conducive to post-maintenance.

  Object oriented programs are dependent on the abstract, without depending on the specific implementation, abstract rarely changes. Greatly reducing the customer application and implementation details of the coupling to enhance the robustness of the software architecture. Abstract does not change as long as it does not require much change, follow the Dependency Inversion Principle .

  To make use of an abstract type in the program as an object instance variable type, thus ensuring decoupling between the client and the specific implementation, because of the use of abstract type, so change will not affect the concrete realization of abstract type of change.

3. The multi-purpose combination of less inheritance

  In object-oriented software design, for the extension class, the first thought is to use class inheritance to achieve, to inherit the parent class by subclasses, thus completing the expansion of the sub-class functionality. The benefits of inheritance is try to make the same attribute or function multiplexing, but as the project is growing, changing needs, inheritance will become more and more bloated, the latter is difficult to control and maintain. Most importantly, the inheritance will be indiscriminate white, the public and protected methods of the parent class inherit all, and these methods may be a subclass of unwanted features, will subclass generate some harm.

  If you use a combination the succession problem would not arise. The so-called target combination, means a further reference to an object in an object, so that the internal reference can be used to make some object handling behavior. The benefits of using combinations of the following points: First, do not adversely affect the class; secondly, combinations flexible than inheritance, because it is determined by the system to run dynamically using an object or not; and finally, because not cause class inheritance due to expansion, reducing the dependency of the parent class.

  Or combination of objects called nested model, by assigning different types of objects between each other to complete

"" " 
Create three schools and three school facilities and other contents are the same. 
" "" 

Class School (Object): 
    DEF __init __ (Self, name, address): 
        self.name = name 
        self.address = address 

    DEF Speech (Self): 
        Print ( 'lecture') 

obj1 = School ( 'Beijing campus,' 'the beautiful and rich River ") 
obj2 = School (' Shanghai campus ',' Pudong New Area ') 
obj3 = School (' Shenzhen campus, '' Nanshan District ') 

class Teacher (Object): 
    DEF the __init __ (Self, name, Age, the salary): 
        the self.name name = 
        self.age = Age 
        Self .__ the salary the salary = 
        self.school None = 

T1 = Teacher (' Jie ' ,. 19, 188 888) 
T2 = Teacher ( 'Yan Tao', 18,60) 
T3 = Teacher ( 'goddess', 16, 900000) 
 
# ############## teacher assigned campus
t1.school = OBJ1
= obj1 t2.school 
t3.school = obj2 

# ############################## 
# Check t1 teacher, where the district name / address 
Print (t1.school.name) 
Print (t1.school.address) 
Print (t1.name) 
Print (t1.age) 
t1.school.speech ()

4. "on - off" Principles

  "Open - closed" principle, namely "open for extension, but closed for modification" refers to the software design, when the extension of a software entity, try not to modify existing software entities, in other words, It is extended without modifying the original software entity. This software design approach is actually a goal, it takes into account other factors such as maintenance software later. If a software system can achieve this, then it is scalable and easy to maintain.

  In the field of software design, the application of a number of design patterns is to achieve this goal. "Open - closed" principle is a very abstract design principles advocated more like a slogan, other design principle is to achieve "open - closed" principle of specific principles. "Open - closed" design principles and other principles like the same relationship between the father and son abstract class.

(Decorator)

 

 

 

 

Master the opening and closing principle is, it tells us to open for extension, but closed for modification; (open for extension, closed for modification) ------ decorator?

Richter substitution principle tells us not to destroy the inheritance hierarchy; (rational use of inheritance, do not mess with inheritance) ---- kiwi bird's flight can not inherit function

Dependency Inversion Principle tells us to be oriented programming interface; (abstract-oriented programming) ------ object-oriented programming

Single Responsibility Principle tells us to implement a single class duties; (a class is only responsible for a feature)

Interface Segregation Principle tells us to streamline the design of the interface when single; (increase cohesion reduce coupling, closure function)

Demeter tells us to reduce the coupling; (high cohesion, low coupling)

Synthesis of multiplexing principle tells us to be preferentially used in combination or aggregation relationship multiplexing, less inheritance reuse. (Multi-purpose compositions with less inheritance, i.e., a combination of nested)

Guess you like

Origin www.cnblogs.com/shuimohei/p/11627178.html