1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.

Slides:



Advertisements
Similar presentations
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
Advertisements

AP 04/02 Structural Patterns Describe how classes and objects are composed to form larger structures Structural class patterns use inheritance to compose.
02 - Structural Design Patterns – 1 Moshe Fresko Bar-Ilan University תשס"ח 2008.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Bridge Pattern.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Structural Patterns - Page L6-1 PS95&96-MEF-L13-1 Dr. M.E. Fayad Creationa l Paradigm.
Bridge The decoupling of abstraction and implementation.
Chapter 8, Object Design Introduction to Design Patterns
Design Patterns. CS351 - Software Engineering (AY2007)Slide 2 Behavioral patterns Suppose we have an aggregate data structure and we wish to access the.
Adapters Presented By Zachary Dea. Definition A pattern found in class diagrams in which you are able to reuse an ‘adaptee’ class by providing a class,
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Design Pattern – Bridge (Structural) References Yih-shoung Chen, Department of Information Engineering, Feng Chia University,Taiwan, R.O.C. The Bridge.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
Composite Design Pattern. Motivation – Dynamic Structure.
Design Patterns.
1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade pattern.
ADAPTER PATTERN BY Sravanthi Karumanchi. Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
GoF Sections Design Problems and Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Decorator Explained. Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub-classing for.
GoF: Document Editor Example Rebecca Miller-Webster.
SDP Structural Pattern. SDP-2 Structural Patterns Concerned with how classes and objects are composed to form large structures Class Patterns use.
Structural Design Patterns
ECE450S – Software Engineering II
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns V More Structural Patterns.
Design Patterns Structural Patterns. Adapter Convert the interface of a class into another interface clients expect Adapter lets classes work together.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm.
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
Pattern Bridge. Definition Bridge is the structural pattern that separates abstraction from the implementation so that both of them can be changed independently.
Bridge Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern.
S.Ducasse Stéphane Ducasse 1 Decorator.
The Decorator Pattern (Structural) ©SoftMoore ConsultingSlide 1.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
CS 5150 Software Engineering Lecture 16 Program Design 3.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
Adaptor Bridge Composite UNIT-IV1 Repeated key points for Structural Patterns (Intent, Motivation, Also Known As…) Code Examples Reference
S.Ducasse Stéphane Ducasse 1 Adapter.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Structural Patterns Structural patterns control the relationships between large portions of your applications. Structural patterns affect applications.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Behavioral Design Patterns
More Design Patterns 1.
Design Patterns Satya Puvvada Satya Puvvada.
More Design Patterns 1.
Decorator Intent Also known as Wrapper Example: a Text Window
Decorator Pattern Intent
Jim Fawcett CSE776 – Design Patterns Summer 2003
Informatics 122 Software Design II
Object Oriented Design Patterns - Structural Patterns
Decorator Pattern Richard Gesick.
BRIDGE PATTERN.
Structural Pattern part-I introduction
Structural Patterns: Adapter and Bridge
Informatics 122 Software Design II
Decorator Pattern.
Adapter Pattern Jim Fawcett
Software Design Lecture 10.
Adapter Pattern Jim Fawcett
Presentation transcript:

1 Structural Design Patterns - Neeraj Ray

2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator

3 Adapter (Wrapper) - Intent Convert the interface of a class into another interface that clients expect.

4 Adapter - Motivation Suppose your organization has a useful class Customer with operations getName() and addAccount(). The application you are building is filled with references to an abstract interface called Cust, with operations name() and addAcc() etc., and a concrete subclass BankCust. You want to be able to use Customer without changing the application you are building.

5 Adapter - Example Customer + addAcc () Cust + addAccount () > Client BankCust + addAccount () customer.addAcc()

6 Object Adapter - Structure Target + request () > Client adaptee.specificRequest() Adapter + request () Adaptee + specificRequest ()

7 Class Adapter - Structure Client Target + request () > Adaptee + specificRequest () Adapter + request () specificRequest()

8 Adapter - Applicability n To use an existing class, and its interface does not match the one you need. n To create a reusable class that cooperates with classes that don’t have compatible interfaces. n (Object adapter only) To use several existing subclasses, but it can be impractical to adapt their interfaces by subclassing every one. An object adapter can adapt the interface of its parent.

9 Class Adapter - Consequences : Lets Adapter override some of the Adaptee’s behavior, since Adapter is a subclass of Adaptee. : Introduces only one object, and no additional pointer indirection is needed to get to the Adapter. è Adapts Adaptee to Target by committing to a concrete Adapter class. As a consequence, a class adapter won’t work when we want to adapt a class and all its subclasses.

10 Object Adapter - Consequences : Lets a single Adapter work with many Adaptee’s-- i.e., the Adaptee itself and all of its subclasses. è Makes it harder to override Adaptee’s behavior.

11 Adapter - Other Issues n How much adapting should an Adapter do? It depends on how similar the Target interface is to Adaptee’s. n Using two-way adapters -- making two separate interfaces work as both Adapter and Adaptee. n Pluggable interface -- design an interface for adaptation. This is similar to the idea of Open Implementation. This can be designed using Adapter design pattern.

12 Bridge - Intent Decouple an abstraction from an implementation so that the two can vary independently.

13 Bridge - Motivation Inheritance binds an implementation to the abstraction permanently, which makes it difficult to modify, extend and reuse abstractions and implementations independently.

14 Bridge - Motivation (Cont.) Window XWindow PMWindow IconWindow XWindowIconPMWindowIcon

15 Bridge - Motivation (Cont.) n It is inconvenient to extend the window abstraction to cover different kinds of windows or new platform. n It makes the client-code platform dependent.

16 Bridge - Example XWindow drawLine () drawText () PMWindow drawLine () drawText () IconWindow WindowImpl drawLine () drawText () > Window drawRect () > impl.drawLine()

17 Bridge - Structure ConcreteImplentorB implOperation () RefinedAbstraction ConcreteImplementorA implOperation () Implementor implOperation () > Abstraction operation () > impl.implOperation()

18 Bridge - Applicability n To avoid a permanent binding between an abstraction and its implementation. Specific implementation can be selected at run-time n To independently extend abstraction and implementation by subclassing. Different abstractions can be combined with different implementations. n Changes in the implementation of an abstraction should have no impact on the clients.

19 Bridge - Applicability (Cont.) n To avoid proliferation of classes as shown in the Motivation section. n To share an implementation among multiple objects. e.g. Handle/Body from Coplien.

20 Bridge - Consequences : Decoupling interface and implementation. : Improved extensibility of both abstraction and implementation class hierarchies. : Hiding implementation detail from client.

21 Bridge - Related Patterns n Similar structure to Adapter but different intent. n Abstract Factory pattern can be used with the Bridge for creating objects.

22 Composite - Intent Compose objects into tree structure to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

23 Composition - Motivation Classes for containers (e.g.. Rectangle) and primitives (e.g.. Line) are designed separately, but in many cases the client wants to treat the container and the primitive identically. The Composite pattern describes how to use recursive compositions so that clients don’t have to make this distinction.

24 Composite - Example 0..* LineText Rectangle Graphic + draw () + add (g : Graphic) + remove (g : Graphic) + getChild (int) > Picture draw (g : Graphic) add (g : Graphic) remove (g : Graphic) getChild () 0..* draw(){ for all g in graphics g.draw() }

25 Composite - Structure Leaf + operation () Composite + operation () + add () + remove () + getChildren () Component + operation () + add () + remove () + getChildren () > 0..* children operation(){ for all g in graphics g.operation() }

26 Composite - Applicability n To represent part-whole hierarchies of objects. n To be able to ignore the differences between containers and primitives. Clients will treat all objects in the composite pattern uniformly.

27 Composite - Consequences : Clients can treat composite structures (containers) and individual objects (primitives) uniformly. : Composite makes it easier to add new kinds of components (leaf or composite). è Can make the design overly general. Sometimes you want the composite to have certain kinds of components.

28 Decorator - Intent Attach additional responsibility to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

29 Decorator - Motivation Suppose that bank application must deal with many different varieties of customers (having checking only, checking and money-market fund and safe-deposit box etc.) The combinatorial varieties are too much to handle using one big class.

30 Decorator - Example getBalance{ accComponent.getBalance();} AccountInfo + getBalance () CheckingAccount + getBalance () SavingAccount + getBalance () + calculateBalance () + getInterestRate () MMFAccount + getBalance () AccountComponet + getBalance () > AccountDecortor + getBalance () > 1..1 getBalance(){ super.getBalance(); calculateBalance();}

31 Decorator - Structure Decorator + operation () > ConcreteComponent + operation () ConcreteDecoratorA - addedState + operation () ConcreteDecorator + operation () + addedBehavior () Component (from Composition) + operation () > 1..1

32 Decorator - Applicability n To add responsibility to individual objects dynamically and transparently, that is, without affecting other objects. n For responsibility that can be withdrawn. n When extension by subclassing is impractical.

33 Decorator - Consequences : More flexibility than static inheritance - responsibilities can be added and removed at run- time. : Avoids feature-laden classes high up in the hierarchy. Responsibility is added on demand. è Lots of little objects. Decorator may produce a system with lots of little look-alike objects. The objects only differ in the way they are interconnected. These systems can be hard to learn and debug.

34 Decorator - Related Patterns n Adapter gives an object a completely new interface, whereas the Decorator changes an object’s responsibility but not its interface. n Decorator can be used with a Composite to represent a whole-part relationship.

35 Next Pattern Presentation n More Structural Patterns u Facade u Flyweight u Proxy n Behavioral Patterns u Chain of Responsibility u Command u Interpreter u … And more