摘要:
组合模式定义:Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.将对象组合成树形结构以表示“部分-整体”的层次结构,使得用户对单个对象和组合对象的使用具有一致性。 如上图所示 阅读全文
摘要:
观察者模式定义:Define a one-to-many dependency between objects so that when one object changes state, all its dependents aer notified and updated automatically.定义对象间一种一对多的依赖关系,使得当一个对象改变状态,则所有依赖于它的对象都会得到通知并被自动更新。 如上图所示 阅读全文
摘要:
单例模式定义:Ensure a class has only one instance, and provide a global point of access to it.动态确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例。 如上图所示(截取自《Head First Design Patterns》一书)。通过使用private的构造函数确保了在一个应用中产生一个实例,并且是自行实例化(在Singleton中自己使用new Singleton())。二、单例模式优势由于单例模式在内存 阅读全文
摘要:
装饰模式定义:Attach additional responsibilities to an object dynamically keeping the same interface. Decoators provide a flexible alternative to subclassing for extending functionality.动态地给一个对象添加一些额外的职责。就增加功能来说,装饰模式相比生成子类更为灵活。 如上图所示(截取自《Head First Design Patterns 阅读全文