西维蜀黍

【Design Pattern】Strctural - Composite

动机

  • 希望表达具有层次结构(部分-整体,part-whole)的实体
  • 对调用者来说,叶子元素和复合元素都是一样的
  ...


【Design Pattern】Structural - Adapter

Adapter Pattern

  • The adapter design pattern solves problems like:

    • How can a class be reused that does not have an interface that a client requires?
    • How can classes that have incompatible interfaces work together?
    • How can an alternative interface be provided for a class?

    Often an (already existing) class can’t be reused only because its interface doesn’t conform to the interface clients require.

  ...


【Design Pattern】Structural - Flyweight/ Object Pool

1 动机

通过尽可能共享对象中的数据来实现对内存的最小化使用,这就是享元模式的动机。

一个典型的例子是:在Word中,对字符的图形化展现。如果每一个显示的字符都对应一个独立的对象,这将会消耗大量的内存。取而代之,位于文档中不同位置的相同字符会共享大部分属性,而只有字符位置这样的属性才需要被单独保存。

  ...


【Design Pattern】Behavioural - Observer

1 定义

观察者模式(Observer Pattern)定义了一种一对多的依赖对象关系,使得当那一个对象状态发生改变时,依赖它的多个对象均能得到通知并自动更新(做出相应反应)。

  ...


【Design Pattern】Behavioural - Chain of Responsibility Pattern

Intent

Chain of Responsibility is a behavioral design pattern that lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request or to pass it to the next handler in the chain.

  ...