Coder Social home page Coder Social logo

-'s Introduction

设计模式python

单一职责原则

一个类只负责一个职责,不应该有过多的概括范围,多拆分类。

开闭原则

对扩展开放,对修改关闭,类模块应该是可扩展的,但是不可修改。

里氏代换原则

任何基类可以出现的地方,子类一定可以出现,子类尽量不要重写父类的方法,可以用组合,聚合的方式来达到目的,继承表达类型抽象。

依赖倒转

上层模块不依赖下层模块,抽象不依赖细节,细节要依赖抽象,多以抽象方式更加稳定,高层模块(稳定)不应该依赖于低层模块(变化),二者都应该依赖于抽象(稳定) 。
抽象(稳定)不应该依赖于实现细节(变化) ,实现细节应该依赖于抽象(稳定)。

接口隔离原则

继承会增加依赖的内容,对于接口的功能要单一化,不能过于复杂,不应该强迫客户程序依赖它们不用的方法。接口应该小而完备。

迪米特原则

最少知道原则,一个类对对象的使用,应该尽可能不去了解对象,只是用对象的公开接口。
不要在类内使用新类作为局部变量,尽可能降低类直接的依赖,只能和入参和出参类交互
不将变量类型声明为某个特定的具体类,而是声明为某个接口。
客户程序无需获知对象的具体类型,只需要知道对象所具有的接口。
减少系统中各部分的依赖关系,从而实现“高内聚、松耦合”的类型设计方案

合成复用原则

尽量使用合成、聚合的方式,而不是使用继承。
类继承通常为“白箱复用”,对象组合通常为“黑箱复用” 。
继承在某种程度上破坏了封装性,子类父类耦合度高。
而对象组合则只要求被组合的对象具有良好定义的接口,耦合度低。

封装变化

使用封装来创建对象之间的分界层,让设计者可以
在分界层的一侧进行修改,而不会对另一侧产生不良的影响,从而实现层次间的松耦合

-'s People

Contributors

qiangzhu123 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.