Design Patterns

Design Patterns Design Patterns: Elements of Reusable Object-Oriented Software is a software engineering book describing software design patterns. The book’s authors are Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides with a foreword by Grady Booch. The book is divided into two parts, with the first two chapters exploring the capabilities and pitfalls of […]

Template Method

1. Usage Define the skeleton of an algorithm in base class “Template Method” Steps required concrete implementation define as placeholders in base class Derifed classes fill-up placeholders with concrete implementations 2. UML class diagram 3. Pros shields the client from the details of the variant behaviour quality & productivity – only the variant behaviour needs […]

State Pattern

1. Usage Allow an object to change behavior when State changed. implements OOP Final State Machine(FSM) 2. UML class diagram Context is wrapper class – interface to state Define abstract state base class Define state specific behavior in derived state classes maintain pointer to current state in wrapper context class 3. Pros Easier to extend […]

Observer pattern

1. Usage Pattern Observer – define relationship “one to many” such way that when state of object change all dependent objects notified/updated automatically. Pattern Observer encapsulate main component in Subject abstraction and dependent objects in Observer hierarchy. Observer used IN MVC as View part This pattern used widely in User interfaces. 2. UML class diagram […]

Strategy Pattern

1. Usage Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from the clients that use it. Capture the abstraction in an interface, bury implementation details in derived classes. 2. UML class diagram 3. Pros greater flexibility, reuse can change algorithms dynamically 4. Cons strategy creation […]

Command pattern

1. Usage Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. The purpose of the Command pattern is to decouple an event generator (the Invoker) from the event handler (the Receiver). A ConcreteCommand class (sub-classed from Command) defines an execute ()method which […]

Iterator pattern

1. Usage Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. makes possible to decouple collection classes and algorithms. Promote to “full object status” the traversal of a collection. Polymorphic traversal 2. UML class diagram 3. Pros shields the client from the internal representation of aggregator. aggregate […]

Interpreter pattern

1. Usage Specialized database query languages such as SQL,RegExp. Specialized computer languages which are often used to describe communication protocols. Most general-purpose computer languages actually incorporate several specialized languages.(lua script inside game engine) 2. UML class diagram AbstractExpression Declares an abstract Interpret operation that is common to all nodes in the abstract syntax tree. TerminalExpression […]