随笔分类 -  设计模式

摘要:The Factory Method Pattern defines an interface for creating an object, but lets subclassed decide which classto instantiate. Factory Method lets a class defer instantiation to subclasses.Dependency Inversion PrincipleDepend upon abstractions. Do not depenfd upon concrete classesGuidelies to follow 阅读全文
posted @ 2012-05-05 17:47 qiangzhu 阅读(524) 评论(0) 推荐(0)
摘要:The Composite Pattern allows you to compose objects into tree structures to represent part-wholehierarchies.Composite lets clients treat individual objects and compositions of objects uniformly.The Composite Pattern allows us to build structures of objects in the form of trees that contain bothcompo 阅读全文
posted @ 2012-05-03 20:48 qiangzhu 阅读(477) 评论(0) 推荐(0)
摘要:The Iterator Pattern provides a way to access the elements of an aggregate object sequentially withoutexposing its underlying representation 阅读全文
posted @ 2012-04-27 21:47 qiangzhu 阅读(494) 评论(0) 推荐(0)
摘要:The Template Method Pattern defines the skeleton of algorithm in a method, define some steps tosubclasses. Template Method lets subclass redefine certain steps of an algorithm without changingthe algorithm's structrue.Class diagram:abstract class AbstractClass{ final void templateMethod(){ primi 阅读全文
posted @ 2012-04-27 21:19 qiangzhu 阅读(482) 评论(0) 推荐(0)
摘要:Design Principle(Open-Closed Principle)Classes should be open for extension, but closed for modification.The Decorator Pattern attaches additional responsibilitis to an object dynamically.Decorator provide a flexible alternative to subclassing for extending functionality.public abstract class Bevera 阅读全文
posted @ 2012-04-25 14:33 qiangzhu 阅读(455) 评论(0) 推荐(0)
摘要:The Observer Pattern defines a one-to-many dependency between objects so that when oneobject changes state, all of its dependents are notified and updated automatically.The Observer Pattern defines a one-to-many relatioship between objects.Design PrincipleStrive for loosely coupled designs between o 阅读全文
posted @ 2012-04-25 11:33 qiangzhu 阅读(466) 评论(0) 推荐(0)
摘要:Design Principle:Identify the aspects of your application that vary and sparate them from what stays the same.Program to an interface, not an implementation.Favor composition over inheritanceThe Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable.St 阅读全文
posted @ 2012-04-25 11:05 qiangzhu 阅读(374) 评论(0) 推荐(0)
摘要:The Facade Pattern provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher-levelinterface that makes the subsystem easier to use.A facade not only simplifies an interface, it decouples a client from a subsystem of components.Facades and adapters may wrap multiple 阅读全文
posted @ 2012-04-24 16:35 qiangzhu 阅读(444) 评论(0) 推荐(0)
摘要:The Adapter Pattern converts the interface of a class into another interface the clients expect.Adapter lets classedwork togetherthat couldn't otherwise because of imcompatible interfaces.Object and class adaptersclass diagramThe only difference is that with class adapter we subclass the Target 阅读全文
posted @ 2012-04-24 16:01 qiangzhu 阅读(531) 评论(0) 推荐(0)
摘要:Command Pattern allows you to decouple the requester of an action from the object actually performs the action. A commandobject encapsulates a request to do something on a specific object.From dinner to the Command Pattern1.Implementing the Command interfacepublic interface Command{ public void exe. 阅读全文
posted @ 2012-04-18 17:52 qiangzhu 阅读(697) 评论(0) 推荐(0)