Several principles of software design patterns

xiaoxiao2021-03-05  28

Mode is a kind of concept, architectural model, design model, marketing model, business operation mode. All industries have its own model.

The design pattern here is the mode in the software design, mainly refers to the object-oriented software design. Follow the design mode, effectively improve the user-maintainability and reusability of software, improve the efficiency of development software, and avoid excessive reproduction wheels.

My learning model is "design mode" from the top of the top of the big name, truly feel the benefits of designing the design model to software design. "Design mode" is refined, few instances, my understanding is too bad, in actual learning, I am java Java in conjunction with Jeffyyan.

Several principles of design software, this is also the essence of design patterns:

1. Open-Closed principle

1). The needs of customers are unstable. By expanding the existing software system instead of modifying the software system to meet the needs of customers, such software systems meet the opening-closed principles, that is, software systems must have certain flexibility. And adaptability.

2). Existing modules, especially the module of the abstract layer cannot be modified, ensuring the stability and continuation of the software system.

The key to solving the problem is abstraction, separating it with specific implementation. Interface (Interface), abstract class application

For variable encapsulation: package variability into an object.

2. Abstract class

The abstract class does not have an example, generally as a parent class for subclass inheritance, generally containing the common attributes and methods of this system.

Note: In the good inheritance relationship, only the leaf node is specific class, other nodes should be an abstract class, that is, the specific class

It is not inherited. Place as much common as possible in the abstraction class.

3. Replacement principle

Subclasses can be replaced in places where there is a base class.

When two specific classes violate the Principles of Rivie, an approach is abstract, as the parent class of these two classes,

One is to apply a combination aggregation relationship establishment relationship.

Do not abuse inheritance in order to use certain types of methods (function).

4 dependency reversal principle

Abstract should not depend on and details, the details should depend on abstract.

To program, not for the interface, not for implementation.

Transfer parameters, or in combination aggregation relationships, try to reference the hierarchical class.

It is mainly to create various specific objects when constructing objects, of course, if some specific classes are stable, do not have to make a parent class with an abstract class, this is the feeling of touching

5 principle of interface isolation

Examples of customization services, each interface should be a role, not many, things that don't do it, the doing thing must do

6 synthesis / polymerization principle

Try to use the synthetic aggregation principle, use less inheritance.

Synthesis: One glory, one loss, the same life cycle is the same

Aggregation: The portion can be part of the overall, or may be exist from the whole.

Distingify HAS A and IS A problem

7 Dimit Block

Minimum knowledge principle. Don't talk to strangers.

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

New Post(0)