Object-Oriented Design Principles (7) CCP (principle of joint closure)

Source: Internet
Author: User
CCP (the common closure principle)

All classes in the package should be closed for changes to the same class nature.

 

The classes in a package shoshould be closed together against the same kinds of changes. A change that affects a package affects all the classes in that package.

All classes in a package should be disabled for changes of the same type. A change affects a package and affects all classes in the package.

A more brief statement is:

Classes that change together, belong together.

Classes modified together should be combined (in the same package ).

If you have to modify the code in the application, we want all the modifications to occur in a package (change to close) instead of in many packages.

The CCP principle is to combine all classes that need to be modified for the same reason into a package. If the two classes are physically or conceptually closely related and they change together, they should belong to the same package.

CCP has a deep relationship with the principle of open and closed (OCP: open closed principle). Closure is what OCP advocates: classes shoshould be closed for modification but open for extension. class should be closed for modification and open for extension. But we know that 100% of the "close" is unrealistic. When designing a system, we can only try to keep the most foreseeable changes closed.

The CCP extends the "close" concept of OCP. When you need to modify it for some reason, you must restrict the scope to be modified to a minimum package.

The CCP principle helps us determine which classes should be placed in the same package.

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.