Java Design Pattern Principles

Source: Internet
Author: User

1. find out where you might need to change in your application, separate them, and don't mix with code that doesn't need to change.

In other words, if every new requirement comes, it will change the code in some aspect, then you can be sure that this part of the code needs to be extracted, and other stable code to distinguish.

Alternatively, take the changed parts out and wrap them so that you can easily change or expand the sub-sections later without affecting other parts that don't need to change.

2. Programming for the interface, not the implementation

"Programming for interfaces" really means "programming for Hyper-type (supertype)"

Here the so-called "interface" has multiple meanings, the interface is a "concept", is also a Java interface construction. You can "program for interfaces" without involving Java interface, and the key is polymorphic. Using polymorphism, programs can be programmed for super-type execution, which executes to real behavior based on actual conditions and is not tied to the behavior of super-type. The phrase "programming for super-type" can be more explicitly "variable declaration type should be a super-type, usually an abstract class or an interface, so as long as the specific implementation of this superclass class produces objects, can be assigned to this variable." This also means that declaring a class ignores the actual object type at the time of execution.

"Programming for Interfaces" is a good solution to the coupling, making the code and thinking more hierarchical and easier to update later in the code.

Java Design Pattern Principles

Related Article

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.