1. Intention: more understandable, easier to maintain and easier to extend.(通过良好的设计使得代码easy and simple,从而实现将复杂的事情简单化)
  2. S — Single responsibility principle
    1. every module or class should have responsibility over a single part of the functionality provided by the software
    2. 一个class就让它做一件事,保持类的简单
    3. 比如现在处理一个将输入数据处理并传送到前端的业务,在这里就至少有两个类,一个类负责数据的处理,一个类负责将数据输出成不同的形式(xml,json…)
  3. O — Open/closed principle
    1. software entities (classes, modules, functions, etc.) should be open for extensions, but closed for modification
    2. how to: utilizing(利用) inheritance and/or implementing interfaces that enable classes to polymorphically substitute(替代) for each other
    3. 当需求发生变更时优先考虑扩展(比如使用继承或实现接口产生新的class)而不是修改原有的代码
  4. L — Liskov substitution principle
    1. if S is a subtype of T, then objects of type T may be replaced (or substituted) with objects of type S.
    2. 确保子类在各方面都能替代父类
      1. 子类可以实现父类的抽象方法,但不能重写父类的非抽象方法(请考虑这种情况下怎么实现多态)
      2. 子类中可以增加自己特有的方法
      3. 当子类的方法重载父类的方法时,方法的前置条件(即方法的形参)要比父类方法的输入参数更宽松
      4. 当子类的方法实现父类的抽象方法时,方法的后置条件(即方法的返回值)要比父类更严格
    3. 请考虑"正方形 IS-A 长方形"的问题(假如它们之间有继承关系,那么计算面积或者周长的时候怎么办?)
    4. 请考虑该原则和开闭原则之间存在的冲突(假如现在需要对父类的非抽象方法进行重写)
  5. I — Interface segregation principle
    1. Clients should not be forced to implement interfaces they do not use
    2. 接口应该定义得足够小,子类在实现的时候不应该觉得某个方法是多余的
  6. D — Dependency inversion principle
    1. High-level modules and low-level modules should depend on abstractions. Details should depend on abstractions.
    2. how to: dependency injection 使用IOC容器来管理class之间的依赖关系

SOLID Principles的更多相关文章

  1. The SOLID principles(未完,待续)

    The SOLID principles The SOLID principles of Object Oriented Design include these five principles: S ...

  2. 浅谈 SOLID 原则的具体使用

    SOLID 是面向对象设计5大重要原则的首字母缩写,当我们设计类和模块时,遵守 SOLID 原则可以让软件更加健壮和稳定.那么,什么是 SOLID 原则呢?本篇文章我将谈谈 SOLID 原则在软件开发 ...

  3. [译]开发者须知的SOLID原则

    原文:SOLID Principles every Developer Should Know – Bits and Pieces SOLID Principles every devloper sh ...

  4. 2.1 OOP & SOLID

    OOP & SOLID Implementing DDD highly relies on the Object Oriented Programming (OOP) and SOLID pr ...

  5. 开放封闭原则(Open Closed Principle)

    在面向对象的设计中有很多流行的思想,比如说 "所有的成员变量都应该设置为私有(Private)","要避免使用全局变量(Global Variables)",& ...

  6. 接口分离原则(Interface Segregation Principle)

    接口分离原则(Interface Segregation Principle)用于处理胖接口(fat interface)所带来的问题.如果类的接口定义暴露了过多的行为,则说明这个类的接口定义内聚程度 ...

  7. 依赖倒置原则(Dependency Inversion Principle)

    很多软件工程师都多少在处理 "Bad Design"时有一些痛苦的经历.如果发现这些 "Bad Design" 的始作俑者就是我们自己时,那感觉就更糟糕了.那么 ...

  8. 里氏替换原则(Liskov Substitution Principle)

    开放封闭原则(Open Closed Principle)是构建可维护性和可重用性代码的基础.它强调设计良好的代码可以不通过修改而扩展,新的功能通过添加新的代码来实现,而不需要更改已有的可工作的代码. ...

  9. 单一职责原则(Single Responsibility Principle)

    单一职责原则(SRP:The Single Responsibility Principle) 一个类应该有且只有一个变化的原因. There should never be more than on ...

随机推荐

  1. Python中的子进程并发

    date: 2019-06-16   22:35:33 author: headsen chen notice:个人原创 实例代码: import os,time time.sleep(1) from ...

  2. keras Dense 层

    文档地址:https://keras.io/layers/core/#dense keras.layers.Dense(units, activation=None, use_bias=True, k ...

  3. 淘宝npm镜像安装失败的问题

    一:背景 心血来潮要简单搞一搞前端运行.打包的东西.结果第一步通过npm安装淘宝npm的时候就出问题了,如图: 二:解决方法 图片显示有点垃圾,但是看出来“Missing write access t ...

  4. js的Map实例

    1.创建实例 let map= new Map(); // 创建 2.对map的写入 // 要添加的对象 let obj1 = {name:'张三', sex:'boy',age: 21}; let ...

  5. 阶段5 3.微服务项目【学成在线】_day18 用户授权_10-前端集成认证授权-需求分析

    4 前端集成认证授权 4.1 需求分析 截至目前认证授权服务端的功能已基本完成,本章实现前端集成认证授权功能. 前端集成认证授权功能需要作如下工作: 1.前端页面校验用户的身份,如果用户没有登录则跳转 ...

  6. iOS 百度地图报私有api的解决方案

    1.Build Settings-->搜索other linker Flags-->将other linker Flags设置为-objc 2.用2.1.1的版本的百度地图 3.换高德地图

  7. rdd的元素打印

    在集群上运行spark程序时,rdd的操作都在worker机上,因此输出rdd的元素将在worker机的标准输出上进行,驱动节点上不会运行,故直接才程序中写如下代码 rdd.foreach(print ...

  8. C# Newtonsoft.Json JObject 操作

    C# Newtonsoft.Json JObject 操作举例 JArray j = new JArray(); JObject obj = new JObject( ") ); JObje ...

  9. iOS-UIToolbar与UISearchBar

    组件_ UIToolbar  /** 1. 顶部toolbar 2. TextField可以以UIBarButtonItem的自定义视图的方式加入toolbar 3. 三个按钮 4. 将UIBarBu ...

  10. Vector3.Angle问题

    Angle角度 public static float Angle(Vector3 from, Vector3 to); 返回的角度总是两个向量之间的较小的角(实测返回不大于 180 度, 并不是 u ...