EPL 603 TOPICS IN SOFTWARE ENGINEERING Lab 6: Design Patterns
Links to Design Pattern Material 1 http://www.oodesign.com/ http://www.vincehuston.org/dp/patterns_quiz.html
Types of Design Patterns 2 Creational Patterns Abstract Factory Builder Factory Method Prototype Singleton Structural Patterns Adapter Bridge Composite Decorator Façade Flyweight Proxy Behavioral Patterns Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer Strategy Template Method Visitor
Abstract Factory 3 Provides an interface for creating families of related or dependent objects without specifying their concrete classes A level of indirection that provides creation services Supports a family of products Supports many creation strategies: choice of derived class, reusing cached objects, distributed creation, choice of platform or address space The new statement considered harmful
Builder 4 Separate the construction of a complex object from its representation so that the same construction process can create different representations One common input, many possible outputs Wrapper/delegate structure Wrapper directs the algorithm of creation/composition Each delegate encapsulates a target output
Factory Method 5 Defines an interface for creating an object, but let subclasses decide which class to instantiate Lets a class defer instantiation to subclasses Indirect creation is carried out through inheritance Virtual constructor The new statement considered harmful
Prototype 6 Specifies the kinds of objects to create using a cloneable instance and creates new objects by copying this instance Indirect creation through delegation clone The new statement considered harmful
Singleton 7 Ensures a class has only one instance, and provides a global point of access to it Enforces a fixed number of instances of a class Lazy initialization Global access
Adapter 8 Converts the interface of a class into another interface clients expect Lets classes work together that otherwise couldn t because of incompatible interfaces Wraps an existing class with a new interface Impedance matches an old component with a new system Wrapper/delegate structure
Bridge 9 Decouples an abstraction from its implementation so that the two can vary independently Allows the implementation to change while the interface remains stable Wrapper/delegate structure Wrapper is a hierarchy that publishes the interface Delegate is a hierarchy that hides implementation baggage Insulation: envelope/letter structure or handle/body structure
Composite 10 Arranges objects into tree structures to represent part-whole hierarchies Lets clients treat individual objects and collections of objects uniformly Recursive composition 1-to-many has a up the is a hierarchy Examples: File system hierarchy GUI (menus, layout managers)
Decorator 11 Attaches additional responsibilities to an object dynamically Provides a flexible alternative to subclassing for extending functionality Recursive composition 1-to-1 has a up the is a hierarchy A single core object wrapped by possibly many optional objects User configuration of optional features to an existing class
Façade 12 Provides a unified interface to a set of interfaces in a subsystem Defines a higher-level interface that makes the subsystem easier to use Wraps an existing system with a new interface A simple entry point to a large sub-system A layer of indirection that hides legacy complexity
Flyweight 13 Uses sharing to support large numbers of fine-grained objects efficiently Highlight How to design dozens of small objects that incur minimal overhead Instance-independent state stays in the class Instance-dependent state is supplied by the customer A factory facilitates object reuse
Proxy 14 Provides a surrogate or placeholder for another object to control access to it An extra level of indirection that provides additional functionality: Distributed communication Auditing, logging Smart pointer Wrapper/delegate structure
Chain of Responsibility 15 Avoids coupling the sender of a request to its receiver by giving more than one object a chance to handle the request Links the receiving objects and passes the request along the list until an object handles it Recursive composition 1-to-1 has a at the top of the is a hierarchy Object-oriented linked list
Command 16 Encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations Object-oriented callback A magic cookie that encapsulates a method invocation Execute
Interpreter 17 Given a language, defines a representation for its grammar along with a processor that uses the representation to parse sentences in the language Recursive composition 1-to-many has a up the is a hierarchy Processes a grammar
Iterator 18 Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation Polymorphic traversal Promotes the traversal of a collection to full object status
Mediator 19 Defines an object that encapsulates how a set of objects interact Promotes loose coupling by keeping objects from referring to each other explicitly, and lets you vary their interaction independently An extra level of indirection that encapsulates the many-to-many relationships between other components Wrapper/delegate structure Wrapper is a mapping object Delegates are a network of collaborating objects A politically-correct manager (or God) object
Memento 20 Without violating encapsulation, captures and externalizes an object's internal state so that the object can be restored to this state later Undo, rollback A magic cookie that encapsulates a check point capability
Observer 21 Defines a 1-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically Wrapper/delegate structure Wrapper encapsulates the core business logic Each delegate provides userconfigurable, optional functionality Example: A data presentation application with graph, bar chart, pie chart, and table views
State 22 Allows an object to alter its behavior when its internal state changes The object will appear to change its class Wrapper/delegate structure Wrapper passes its this pointer Delegate collaborates with wrapper
Strategy 23 Defines a family of algorithms, encapsulates each one, and makes them interchangeable Lets the algorithm vary independently from clients that use it Configures choice of algorithm Wrapper/delegate structure The client is the wrapper The algorithm object is the delegate
Template Method 24 Defines the skeleton of an algorithm in an operation, deferring some steps to subclasses Lets subclasses redefine certain steps of an algorithm without changing the algorithm s structure Configures steps of an algorithm Placeholders are specified in base class, and implemented in derived classes
Visitor 25 Represents an operation to be performed on the elements of an object structure Lets you define a new operation without changing the classes of the elements on which it operates Double dispatch Do the right thing based on the type of two objects Add operations to an existing hierarchy