Giter VIP home page Giter VIP logo

designschema's Introduction

DesignSchema

java实现23种设计模式

一、设计模式的分类 总体来说设计模式分为三大类:

//位于CreateModel包中 创建型模式:共 5 种:工厂方法模式、抽象工厂模式、单例模式、建造者模式、原型模式。

//位于StructureModel包中 结构型模式:共 7 种:适配器模式、装饰器模式、代理模式、外观模式、桥接模式、组合模式、享元模式。

//位于ActionModel包中 行为型模式:共 11 种:策略模式、模板方法模式、观察者模式、迭代器模式、责任链模式、 命令模式、备忘录模式、状态模式、访问者模式、中介者模式、解释器模式。

二、设计模式的六大原则 总原则:开闭原则,对扩展开放,对修改关闭 在程序需要进行拓展的时候,不能去修改原有的代码,而是要扩展原有代码,实现一个热插拔的效果

1、单一职责原则 不要存在多于一个导致类变更的原因,也就是说每个类应该实现单一的职责,如若不然,就应该把类拆分。

2、里氏替换原则 里氏代换原则:面向对象设计的基本原则之一。 里氏代换原则中说,任何基类可以出现的地方,子类一定可以出现。

3、依赖倒转原则 这个是开闭原则的基础,具体内容:面向接口编程,依赖于抽象而不依赖于具体。 写代码时用到具体类时,不与具体类交互,而与具体类的上层接口交互。

4、接口隔离原则 这个原则的意思是:每个接口中不存在子类用不到却必须实现的方法,如果不然,就要将接口拆分。 使用多个隔离的接口,比使用单个接口(多个接口方法集合到一个的接口)要好。

5、迪米特法则(最少知道原则) 就是说:一个类对自己依赖的类知道的越少越好。也就是说无论被依赖的类多么复杂, 都应该将逻辑封装在方法的内部,通过public方法提供给外部。 这样当被依赖的类变化时,才能最小的影响该类。 最少知道原则的另一个表达方式是:只与直接的朋友通信。类之间只要有耦合关系,就叫朋友关系。 耦合分为依赖、关联、聚合、组合等。我们称出现为成员变量、方法参数、方法返回值中的类为直接朋友。 局部变量、临时变量则不是直接的朋友。我们要求陌生的类不要作为局部变量出现在类中。

designschema's People

Contributors

jiulu313 avatar

Watchers

James Cloos avatar USA 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.