OOAD读书笔记(八):OO Design Principle

#1: Open-Close printciple (OCP)

Classes should be open for extension and closed for modification

#2:Don't Repeat yourself (DRY)

Avoid duplicate code by abstracting out things that are common and placing thoes things in a single location

#3: The Single Responsibility Printciple (SRP)

Each class in your application should have only one reason to change.

#4: The Liskov Substitution Principle (LSP)

Sub types should substitutable for base type.

Others:

Encapsulate what varies.
Code to an interface rather than to an implementaion.
Classes are about behavior and functionality.

Delegation is when you hand over the responsibility for a particular  task to another class or method.

Use composition to assemble behaviors from other classes.

原文地址:https://www.cnblogs.com/rockniu/p/1402209.html