Design Principles of Java Design Patterns

Source: Internet
Author: User

What is the design pattern? In the process of Learning Object-oriented, we will always come into contact with the pattern from time to time! As our predecessors have mentioned, the design model is a summary of people's experience! In software development, we always encounter some reusable components,CodeSo that we can focus on Object-Oriented Reusable Technology. With the development of Reusable Technology, some fixed models will emerge! They are the so-called design patterns we are learning now! No matter what technology you learn, you must start from the basics. This is my consistent principle! After reading n design patterns, I suddenly found that I still have no idea about the design patterns! Finally, in the Java and pattern book, I see what I want and the principles to be followed by some design patterns:

The first is the cornerstone of reusable design: the open and closed principle, that is, a software entity must be open to expansion and closed to modification! This sentence should not be unfamiliar to people with object-oriented programming experience! No matter what software system, designers always wantSource codeCan be expanded.

The second principle is the Li's replacement principle, which is still well known to us. Its expression is that if a software entity uses a base class, it must be applicable to its subclass, moreover, he cannot detect the differences between its base class object and its subclass object. In fact, anyone who learns object-oriented languages knows that subclasses have some features of the base class except their private resources! In Java, the compiler usually checks whether it complies with the Lee's replacement principle!

The third principle is dependency inversion or dependency inversion. You may have heard of this principle, but another term evolved from it, I think, should be familiar to everyone-IoC (dependency injection ), some people say that IOC is actually a dip. However, I think IOC should be a technology to implement dip. The expression of DIP is: Abstraction should not depend on details, and details should depend on abstraction! Or "It should depend on Interface Programming and should not rely on implementation ". Basically, to achieve the principle of open and closed, dip should be a necessary path! As for the design concept of IOC, I am studying it recently. I will talk about his understanding in another post!

The fourth principle is interface isolation. The dependency of one class on another class should be built on the least interface! This may be hard for us to understand, so I will use another statement: it is better to use multiple special interfaces than to use a single interface! We are writingProgramUsually want to write the interface less, the better, then, we put the code of multiple functions in the same interface! In fact, this is wrong. We should separate different functions and set up special interfaces. This is exactly the principle of interface isolation.

In fact, the above principles have been in contact with us in the process of learning object-oriented programming. The above principles are also the principles of the design model! Understanding these basic theories is of great benefit to the study of design patterns or programming ideas !!!

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.