# 怎样写出好代码——设计原则

### 1. 单一职责原则（Single Responsibility Principle - SRP）

There should never be more than one reason for a class to change.

### 2. 开放封闭原则（Open Closed Principle - OCP）

Software entities like classes, modules and functions should be open for extension but closed for modifications.

### 3. 里氏替换原则（Liskov Substitution Principle - LSP）

Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.

### 4. 最少知识原则（Least Knowledge Principle - LKP）

Only talk to you immediate friends.

### 5. 接口隔离原则（Interface Segregation Principle - ISP）

The dependency of one class to another one should depend on the smallest possible interface.

1. 依赖倒置原则（Dependence Inversion Principle - DIP）

High level modules should not depends upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.

## 三、其他设计原则

### 8. 你不需要它（You aren't gonna need it - YAGNI）

posted @ 2015-10-06 16:07  砺能  阅读(...)  评论(...编辑  收藏