Structural and Behavioral Design Patterns
In this tutorial you will learn about Structural Patterns – Adapter, Bridge, Composite and Proxy. You will also learn about Behavioral Patterns – Iterator and Observer.
Category : Structural Pattern
Design Pattern : Adapter
Brief Description :
Highlights of the Adapter Design Pattern are:
– This is a Structural Design Pattern and focuses on how the objects interact
– relationships/interfaces between entities and objects
– The key players are
- Generic Object with its interface
- Client specific Object with client specific interface
- Adapter Object that adapts the generic interface to the client specific interface
llustration :
Category : Structural Pattern
Design Pattern : Bridge
Brief Description :
Highlights of the Bridge Design Pattern are:
– This is a Structural Design Pattern and focuses on the relationships/interfaces
– between entities and objects
– This pattern provides a certain amount of flexibility by providing a level of abstraction
– to animplementation
– An object (say “Implementor”) implements the functionality
– The client object does not call the “Implementor” Object directly it calls a Wrapper
– object which in turn calls the “Implementor”
– Thus the Wrapper can provide Value additions to the data returned by Implementor
– The Wrapper can be changed without changing Implementor
– The focus of this pattern is to decouple the implementation from the called or (referred to as the interface component wrapper)
Illustration :
Category : Structural Pattern
Design Pattern : Composite
Brief Description :
Highlights of the Composite Design Pattern are:
– This is a Structural Design Pattern and focuses on the relationships/interfaces
– between entitiesand objects
– This pattern comprises of objects that form a tree pattern
– A component may have one or more child components and they in turn may have
– one or morechildren
– For example in a XML document Each node may have one or more child nodes exactly like itself
– The Composite design pattern is suited for scenarios such as these
– Each component can have functionality to add, remove query children
– An element class can provide functionality that could correspond to a “leaf” in the tree
– The element class can be used to perform operations with a data value of that node
– The focus of this pattern is to provide an object with an interface such that the object can have one or more children that have the exact same interface. The hierarchy continues recursively. It also provides a “leaf” object for the “tree” such that it represents any one of the nodes in the entire relationship tree
Illustration :
Category : Structural Pattern Highlights of the Proxy Design Pattern are: Illustration :
Category : Behavioral Pattern Highlights of the Iterator Design Pattern are: Illustrations :
Category : Behavioral Pattern
Illustrations :
Design Pattern : Proxy
Brief Description :
– This is a Structural Design Pattern and focuses on the relationships/interfaces between entities and objects
– The Proxy object provides a level of isolation to the real object
– The Proxy object represents the actual object, the proxy object is like a placeholder
– The Proxy has the same interface as the “real” object
– When a client call the “real” object the call can be routed through the proxy
– This is useful in cases where the “real” object is on a different server
– This is also useful if you do not wish to provide direct access to the “real” object and if you need to perform a security check before calling the “real” object
– The focus of this pattern is to provide a placeholder object called proxy and the proxy has the same interface as the real object
Design Pattern : Iterator
Brief Description :
– This is a Behavioral Design Pattern and focuses on the communication patterns between objects
– The Iterator component provides a way to sequentially access a collection of objects
– Once an Iterator is created the client access the objects in a collection using functions such as getfirst, getcurrent , getNext, etc.
Design Pattern : Observer
Brief Description :
Highlights of the Observer Design Pattern are:
– This is a Behavioral Design Pattern and focuses on the communication patterns between objects
– The observer pattern comprises of an object that serves as an observer for certain events
– One or more observer components are registered with a target object which can be termed as a “Subject”
– If an event occurs such as a mouse click /change of value /etc it notifies the observer
– The observer in turn can call methods/code to act when the event occurs