Design Pattern principle-open and closed principle (I)

Source: Internet
Author: User

This is the most important principle in the object-oriented design principle.

Reading directory

I. Principle of open and closed

Ii. Open and closed principles have two main features:

Iii. Why should we use the open and closed principle?

4. What are the two issues about the principle of openness and closure?

V. Solutions to two problems in the principle of openness and Closure

Vi. Benefits of the open and closed Principle

7. Considerations for the principle of openness and Closure

I. Principle of open and closed

Software entities (classes, modules, functions, etc.) should be extensible, but cannot be modified.

 Ii. Open and closed principles have two main features:

1: open for expansion

2: The modification is closed.

 Iii. Why should we use the open and closed principle?

.When we do not want to determine the requirements of a system from the very beginning, this is an unrealistic and unscientific idea. Since the requirements must change, so how can we maintain relatively easy modification and Stability of the designed websites or software in the face of demand changes, so as not to meet new demands, and redo the whole process. We can achieve this by maintaining the principle of openness and closure.

.To meet new requirementsProgramBy addingCodeCompleted, not by modifying the existing Code

4. What are the two issues about the principle of openness and closure?
The principle of "open and closed" means that when you design a software or website, you should always consider all the changes in demand. If you try to make this class good enough, you will not modify it after writing it, if a new requirement comes and some classes are added to fulfill the new requirement, the original code will remain unchanged.
1: First of all, it is impossible for a person to take into account all the problems comprehensively. If he considers all the problems, he will not be a human, but a crowdsourced security testing.

2: Second, how can a class be written and never modified again?

V. Solutions to two problems in the principle of openness and Closure

When we first write a program, we assume that the demand changes will not happen, but when the demand changes, we will immediately (when there is a small change, try to deal with the possibility of major changes as soon as possible.) construct abstraction to isolate similar changes that will happen later. You cannot wait until the development work is half or long. Consider abstraction, separation was difficult at that time.

Vi. Benefits of the open and closed Principle

Following this principle can bring the maintenance, scalability, reusability, and flexibility claimed in object-oriented technology.

7. Considerations for the principle of openness and Closure

Do not deliberately abstract every part of the application. You should construct an abstraction for the part of the application that frequently changes.

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.