Design Patterns--The Zen reading notes of design patterns

Source: Internet
Author: User

6 Major design principles

1. Single responsibility Principle (SRP): There should be and only one cause for class changes. Interface must be a single responsibility, the design of the class as far as possible only one cause of change.

2. Richter replacement principle (LSP): All references to base classes must be able to transparently use objects of their subclasses. As long as the parent class can appear where the subclass can appear, and the substitution of subclasses will not produce any errors or exceptions, but the reverse is not, where there are subclasses, the parent may not be able to adapt.

  • Subclasses must fully implement the methods of the parent class
  • Subclasses can have their own personalities.
  • input Parameters can be magnified when overriding or implementing a method of a parent class (the precondition of a method in a subclass must be the same or looser than the precondition of a method overridden in a superclass)
  • The output can be scaled down when overriding or implementing a method of the parent class (the return value of a method of a parent class is a type T, and the return value of the same method (overloaded or overridden) of the subclass is S, then the Richter substitution principle requires s to be less than or equal to T.

3. Dependency inversion principle (DIP):

  • The high-level module should not rely on the bottom low-layer module, both should rely on its abstraction;
  • Abstraction should not depend on details;
  • Detail should be dependent on abstraction.

The dependency of a PS object is passed in three ways

One, the constructor passes the dependent object public A (b) {a.b = b}

Second, setter method pass dependent object public Setb (b) {a.b = B}

Iii. Interface Declaration dependent objects

4. Interface Isolation principle

———————— to Be Continued ————————————

Design Patterns--The Zen reading notes of design patterns

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.