1、OO设计原则,什么是设计原则?,设计原则是基本的工具,应用这些规则可以使你的代码更加灵活、更容易维护,更容易扩展。,SRP: The single responsibility principle 单一职责原则,系统中的每一个对象都应该只有一个单独的职责,而所有对象所关注的就是自身职责的完成。 Every object in your system should have a single responsibility ,and all the object s services should be focused on carrying out that single responsibil
2、ity .,DRY : Dont repeat yourself Principle,通过抽取公共部分放置在一个地方避免代码重复. Avoid duplicate code by abstracting out things that are common and placing those thing in a single location .,OCP : Open-Close Principle 开闭原则,类应该对修改关闭,对扩展打开. Classes should be open for extension ,and closed for modification .,LSP: The Liskov substitution principle,子类必须能够替换基类。 Subtypes must be substitutable for their base types .,DIP:依赖倒置原则,高层模块不应该依赖于底层模块,二者都应该依赖于抽象. 抽象不应该依赖于细节,细节应该依赖于抽象.,ISP:接口隔离原则,不应该强迫客户程序依赖它们不需要的使用的方法.,