GithubHelp home page GithubHelp logo

designmode's Introduction

DesignMode

create project for design mode

策略模式:分别封装行为接口,实现算法族,超累里放行为接口对象,在子类中具体设定行为对象。 原则就是:分离变化部分,封装接口,基于接口编程各种功能。此模式让行为算法的变化独立于算法 的使用者.

总结:

  • 分析项目中变化部分与不变化部分
  • 多用组合少用继承;用行为类组合,而不是行为的继承。更有弹性
  • 设计模式没有相应的库直接使用。有些库或框架本身就是用某种模式设计的
  • 如果找不到使用的模式怎么办:可能是对项目的分析不够透彻。实在不行只能用笨方法做

观察者模式:对象之间多对一依赖的一种设计方案,被依赖的对象为Subject,依赖的对象为Observer, Subject通知Observer变化

可以使用java的内置观察者模式:

意义:松耦合,高内聚,隔离影响的意义

注意:因为内置的观察者模式是各一个抽象类而不是接口,所以只能单继承。

装饰者模式:动态的将新功能附加到对象上。在对象功能拓展方便,他比继承更具有弹性

单例模式:确保一个类有且只有一个实例,并提供一个全局访问点

方式:私有构造方法让其不能通过new的方式创建实例,通过内部自己定一个实例,并提供一个访问方法,保证每次返回的对象都是同一个

工厂模式:可以提高系统的拓展性,当需要增加一个新的类型,就需要增加工厂、实体等一系列的文件,增加了系统的复杂度。

命令模式:将请求、命令、动作等封装成对象,这样可以让项目使用这些对象来参数化其他对象。使得命令的请求者和执行者解耦合。

designmode's People

Contributors

fx15151496521 avatar

Watchers

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