DEV Community

菜皮日记
菜皮日记

Posted on

设计模式系列文章

本系列文章介绍常见的设计模式,按照设计模式的类别注意介绍。设计模式一般可分为三种大类型:创建型、结构型,行为型。

  • 创建型:讨论的是如何创建实例,将对象的创建和对象的使用分离。
    • 工厂方法 Factory Method
    • 抽象工厂 Abstract Factory
    • 建造者 Builder
    • 原型 Prototype
    • 单例 Singleton
  • 结构型:讨论的是类和对象之间的复用关系,实现对象之间关系解耦。
    • 适配器 Adapter
    • 桥接(模块化) Bridge
    • 组合(对象树) Composite
    • 装饰器 Decorator
    • 外观 Facade
    • 享元(缓存) Flyweight
    • 代理 Proxy
  • 行为型:讨论的是类和对象之间的交互通信,提高协作效率。
    • 责任链 Chain Of Responsibility
    • 命令 Command
    • 迭代器 Iterator
    • 中介者 Mediator
    • 观察者(发布订阅) Observer
    • 备忘录 Memento
    • 状态 State
    • 策略 Strategy
    • 模板方法 Template Method
    • 访问器 Visitor

设计模式最根本的原则就两条,面向接口编程和组合优于继承。而无论哪种设计模式,必须要回归本质,即能够让使用更加方便,让修改更加便捷,另外也不应该生搬硬套设计模式,还是应该看实际情况做解耦,否则就本末倒置了。

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay