Java Design Pattern principle and java Design Pattern Principle

Source: Internet
Author: User

Java Design Pattern principle and java Design Pattern Principle

1,Identify the potential changes in the application and separate them from those that do not need to be changed.

In other words, if every new requirement changes some code, you can determine that this part of code needs to be extracted to distinguish it from other stable code.

Or, extract and encapsulate the changed parts so that they can be easily modified or expanded in the future without affecting other parts that do not need to be changed.

 

2,For interface programming, rather than implementing Programming

"Programming for interfaces" really means "programming for supertypes"

The so-called "interface" has multiple meanings. An interface is a "concept" and a Java interface structure. When Java interfaces are not involved, the key to "programming for interfaces" is polymorphism. With polymorphism, the program can program super-type, and will execute real behaviors according to the actual situation, without being bound to super-type behaviors. The phrase "super-type programming" can be more specifically said "the variable declaration type should be super-type, usually an abstract class or an interface, you can specify this variable as long as it is the object generated by the class that implements this super type ". This also means that when declaring a class, you do not need to care about the real object type during subsequent execution.

"Programming for interfaces" can be well coupled to make code and thinking more layered and facilitate code updates in the future.

 

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.