降低软件成本，提高研发效能

 软件成本 = 研发阶段人力成本 * 开发时间 + 维护阶段人力成本 * 开发时间 

复用

1.曾经见到过一个表字段存储了多种概念的值，甚至是不同类型的值，如”123” 和“abc”，调用端判断数字和字符串分别执行不同逻辑。

2.一个Product对象，存储了汽车信息，和奶粉信息，调用端判断是汽车还是奶粉

3.一个微服务支持多租户，多租户的行为完全不同，根据租户的type在整个微服务中进行if else判断。

软件设计原则

Code Review标准中所述的那样，

DRP-不要重复你自己(Don't Repeat Yourself)

 public List<Apple> findApple(List<Apple> appleRepo,String color) {

List<Apple> result = new ArrayList<>();

for(Apple apple : appleRepo){

if(apple.getColor().equals(color)){

}

}

return result;

}

}

public List<Apple> findApple(List<Apple> appleRepo,int weight) {

List<Apple> result = new ArrayList<>();

for(Apple apple : appleRepo){

if(apple.getWeight()>=weight){

}

}

return result;

} 

copy paste是造成重复的主要原因之一，所以一定慎用或不用copy paste。

KISS原则（Keep it simple and stupid）&& YAGNI(You Aren’t Gonna Need It)

 The KISS principle states that most systems work best if they are kept simple rather than made complex; therefore simplicity should be a key goal in design and unnecessary complexity should be avoided 

Always implement things when you actually need them, never when you just foresee that you need them.

Decide as late as possible: Delaying decisions as much as possible until they can be made based on facts and not on uncertain assumptions and predictions.



----------------------

COC-约定优于配置(Convention Over Configuration)
-----------------------------------------

maven为什么能流行起来，其中主要原因就是maven约定java目录结构优于ant的自定义配置目录结构。

SOLID原则
-------

### SRP-单一职责(Single Responsibility Principle)


A class or entity should have one and only one reason to change.



### OCP-半开半闭(Open Closed Principle)


Software components should be open for extension, but closed for modification.



### LSP-里氏替换(Liskov Substitution Principle)


Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T.

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



LSP是**多态**的基础，而多态是面向对象的核心，通过多态我们可以灵活的扩展。

### ISP-接口隔离(Interface Segregation Principle)


Clients should not be forced to implement unnecessary methods which they will not use.



### DIP-依赖倒置（Dependency Inversion Principle）


Depend on abstractions, not on concretions

`