Design principles in architecture open and close (OCP)-Java Development Technology-experience the beauty of design patterns and algorithms in architecture

Source: Internet
Author: User


Opening and closing principle OCP (Open for extension,closed for modification). The core idea of open and close principle is that an object is opened to expansion and closed to modification.

In fact, the opening and closing principle means that changes to the class are made by adding code rather than altering the existing code. In other words, once the software developer writes out the code that can be run, it should not change it, but to ensure that it can continue to run, how to do this? This requires the help of abstraction and polymorphism, that is, to abstract the content of the possible changes, so that the abstract part is relatively stable, and the specific implementation layer can be changed and extended.

According to the open and close principle, when we change a software (such as extending other functions), we should make the software change by means of extension, instead of modifying the original code to realize the change.


Design principles in architecture open and close (OCP)-Java Development Technology-experience the beauty of design patterns and algorithms in architecture

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.