Structural Pattern part-I introduction

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.
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.
The Composite Pattern. Owners (No Twins, Expos) Managers (No Twins, Expos) Congress (No Twins, Expos) Media (No Twins, Expos) Radio (No Twins, Expos)
The Bridge Pattern Guang Hu February Overview MotivationMotivation ParticipantsParticipants  Structure  Applicability  Benefits  Drawbacks 
Chapter 8, Object Design Introduction to Design Patterns
ADAPTER PATTERN Ali Zonoozi Design patterns course Advisor: Dr. Noorhoseini Winter 2010.
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
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 ( ) ( ) ( )
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Composite Design Pattern. Motivation – Dynamic Structure.
Design Patterns.
ADAPTER PATTERN BY Sravanthi Karumanchi. Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
SDP Structural Pattern. SDP-2 Structural Patterns Concerned with how classes and objects are composed to form large structures Class Patterns use.
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.
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.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
Design Patterns ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
Java EE Patterns Dan Bugariu.  What is Java EE ?  What is a Pattern ?
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.
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
Structural Patterns C h a p t e r 4 – P a g e 55 StructuralPatterns Design patterns that describe how classes and objects can be combined to form larger.
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.
Presented by FACADE PATTERN
Chapter 8 Object Design: Reuse and Patterns 2.
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Factory Method Pattern
Strategy Design Pattern
Chapter 10 Design Patterns.
Software Design Patterns
A Brief Introduction to Design Patterns
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
By SmartBoard team Adapter pattern.
Introduction to Design Patterns
Behavioral Design Patterns
Chapter 8, Design Patterns Bridge
Factory Method Pattern
Presented by Igor Ivković
Chapter 8, Object Design Introduction to Design Patterns
Design Patterns Satya Puvvada Satya Puvvada.
Design Patterns - A few examples
Design Patterns A Case Study: Designing a Document Editor
Jim Fawcett CSE776 – Design Patterns Summer 2003
Informatics 122 Software Design II
BRIDGE PATTERN.
Structural Patterns: Adapter and Bridge
Strategy Design Pattern
Informatics 122 Software Design II
Chapter 8, Design Patterns Introduction
Composite Design Pattern By Aravind Reddy Patlola.
Presented by Igor Ivković
Decorator Pattern.
Adapter Pattern Jim Fawcett
Software Design Lecture 10.
Adapter Pattern Jim Fawcett
Presentation transcript:

Structural Pattern part-I introduction S. No TOPIC PPT Slides 1 Adaptor Bridge Composite L1 3 – 18 2 L2 19 – 31 3 L3 32 – 37 4 Repeated key points for Structural Patterns L4 38 – 40 5 (Intent, Motivation, Also Known As…) L5 41 – 42 6 Code Examples L6 43 – 44 7 Reference L7 45 – 45 UNIT-III

Agenda Intent & Motivation Structure Applicability Consequences Known Uses Related Patterns References UNIT-III

What is Adapter? Intent: L1 What is Adapter? Intent: Change the interface of a class into another interface which is expected by the client. Also Know As: Wrapper UNIT-III

Motivation L1 1 UNIT-III

L1 Structure (Class) UNIT-III

L1 Structure (Object) UNIT-III

L1 Applicability Use an existing class whose interface does not match the requirement Create a reusable class though the interfaces are not necessary compatible with callers Want to use several existing subclasses, but it is impractical to subclass everyone. (Object Adapter Only) UNIT-III

Class Adapter Pattern Pros Cons Only 1 new object, no additional indirection Less code required than the object Adapter Can override Adaptee's behaviour as required Cons Requires sub-classing (tough for single inheritance) Less flexible than object Adapter UNIT-III

Object Adapter Pattern L1 Object Adapter Pattern Pros More flexible than class Adapter Doesn't require sub-classing to work Adapter works with Adaptee and all of its subclasses Cons Harder to override Adaptee behavior Requires more code to implement properly UNIT-III

L1 Pluggable Adapters implemented with abstract operations UNIT-III

L1 Pluggable Adapters implemented with delegate objects UNIT-III

Two-way Adapters L1 class SquarePeg { public: void virtual squarePegOperation() { blah } } class PegAdapter: public SquarePeg, RoundPeg { public: void virtual roundPegOperation() { add some corners; squarePegOperation(); } void virtual squarePegOperation() { roundPegOperation(); class RoundPeg { public: void virtual roundPegOperation() { blah } } UNIT-III

Adapting Local Classes to RMI Comparison: Increases reusability of local class Improves performance of local class Doesn't use Java single parent by subclassing (uses composition) UNIT-III

L1 Related Patterns Adapter can be similar to the remote form of Proxy. However, Proxy doesn't change interfaces. Decorator enhances another object without changing its interface. Bridge similar structure to Adapter, but different intent. Separates interface from implementation. UNIT-III

L1 Conclusions Allows collaboration between classes with incompatible interfaces Implemented in either class-based (inheritance) or object-based (composition & delegation) manner Useful pattern which promotes reuse and allows integration of diverse software components UNIT-III

L1 Adapter You have legacy code current client Adapter changes interface of legacy code so client can use it Adapter fills the gap b/w two interfaces No changes needed for either legacy code, or client UNIT-III

Adapter (cont.) L1 class NewTime { public: int GetTime() { return m_oldtime.get_time() * 1000 + 8; } private: OldTime m_oldtime; }; UNIT-III

L2 The Bridge Pattern UNIT-III

Overview Intent Also Known As Motivation Participants Structure Applicability Benefits Drawbacks Related Pattern I UNIT-III

BRIDGE (Object Structural) Intent: Decouple as abstraction from its implementation so that the two can vary independently. Also Known As: Handle/Body UNIT-III

L2 Motivation Entry oracleDBEntry FilesysEntry UNIT-III

Motivation Entry Appointment OracleDBTask Task OracleDBApp. FilesysApp. FilesysTask UNIT-III

Motivation Bridge impl Entry PersistentImp. Task Appointment getText() setText() Destroy() PersistentImp. initialize() store() load() Task getPriority() setPriority() Appointment getAlarm() setAlarm() OraclePImp destroy() AccessPImp impl UNIT-III

Participants Abstraction (Entry): - define the abstraction’s interface L2 Participants Abstraction (Entry): - define the abstraction’s interface - maintains a reference to an object of type Implementor Refined Abstraction (Task): - extends the interface defined by Abstraction UNIT-III

Participants (continue) L2 Participants (continue) Implementor (persistentImp): - defines an interface for implementation classes. Typically, this Implementor’s interface provides only primitive menthod ConcreteImplementor (oraclePImp, AccessPImp): - implements the Implementor’s interface UNIT-III

Structure L2 impl RefinedAbstraction ConcreteImplementerA ConcreteImplementerB Implementer OperationImp() Client Abstraction impl UNIT-III

L2 Applicability Want to avoid a permanent binding between an abstraction and implementation. When abstractions and implementations should be extensible through subclassing. When implementation changes should not impact clients. UNIT-III

Applicability (continue) When the implementation should be completely hidden from the client. (C++) When you have a proliferation of classes. When, unknown to the client, implementations are shared among objects. UNIT-III

L2 Benefits Avoid permanent binding between an abstraction and its implementation Avoid nested generalizations Ease adding new implementations Reduce code repetition Allow runtime switching of behavior UNIT-III

Drawbacks Double indirection - “entry” operation are implemented by subclasses of PersistentImp class. Entry class must delegate the message to a PersistentImp subclass which implements the appropriate method. This will have a slight impact on performance. UNIT-III

Composite Pattern Intent : L2 Composite Pattern Intent : Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. UNIT-III

Consequences decoupling interface & implementation - implementation of abstraction - can be configured at run-time - eliminate compile time dependencies on implementation - encourages layering improved extensibility - Abstraction & Implementer - can be extended independently hiding implementation details from clients UNIT-III

L3 Composite Pattern Facilitates the composition of objects into tree structures that represent part-whole hierarchies. These hierarchies consist of both primitive and composite objects. UNIT-III

L3 UNIT-III

L3 Observations The Component (Graphic) is an abstract class that declares the interface for the objects in the pattern. As the interface, it declares methods (such as Draw) that are specific to the graphical objects. Line, Rectangle, and Text are so-called Leafs, which are subclasses that implement Draw to draw lines, rectangles, and text, respectively. UNIT-III

Observations (Continued) L3 Observations (Continued) The Picture class represents a number of graphics objects. It can call Draw on its children and also uses children to compose pictures using primitive objects. UNIT-III

Concluding Considerations The Composite Pattern is used to represent part-whole object hierarchies. Clients interact with objects through the component class. It enables clients to to ignore the specifics of which leaf or composite class they use. Can be used recursively, so that Display can show both flares and stars. New components can easily be added to a design. UNIT-III

BRIDGE (Object Structural) Intent: Decouple as abstraction from its implementation so that the two can vary independently. Also Known As: Handle/Body UNIT-III

L4 Motivation Entry oracleDBEntry FilesysEntry UNIT-III

Motivation Entry Appointment OracleDBTask Task OracleDBApp. FilesysApp. FilesysTask UNIT-III

Two-way Adapters L5 class SquarePeg { public: void virtual squarePegOperation() { blah } } class PegAdapter: public SquarePeg, RoundPeg { public: void virtual roundPegOperation() { add some corners; squarePegOperation(); } void virtual squarePegOperation() { roundPegOperation(); class RoundPeg { public: void virtual roundPegOperation() { blah } } UNIT-III

Adapting Local Classes to RMI Comparison: Increases reusability of local class Improves performance of local class Doesn't use Java single parent by subclassing (uses composition) UNIT-III

Motivation Bridge impl Entry PersistentImp. Task Appointment getText() setText() Destroy() PersistentImp. initialize() store() load() Task getPriority() setPriority() Appointment getAlarm() setAlarm() OraclePImp destroy() AccessPImp impl UNIT-III

Participants Abstraction (Entry): - define the abstraction’s interface L6 Participants Abstraction (Entry): - define the abstraction’s interface - maintains a reference to an object of type Implementor Refined Abstraction (Task): - extends the interface defined by Abstraction UNIT-III

L7 References Becker, Dan. Design networked applications in RMI using the Adapter design pattern. JavaWorld Magazine, May 1999. http://www.javaworld.com/javaworld/jw- 05-1999/jw-05-networked.html Buschmann et al. A System of Patterns: Pattern-Oriented Software Architecture. John Wiley and Sons. Chichester. 1996 Gamma et al. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley. Boston. 1995 Nguyen, D.X. Tutorial 10: Stacks and Queues: The Adapter Pattern. Rice University. 1999. http://www.owlnet.rice.edu/~comp212/99- fall/tutorials/10/tutorial10.html Whitney, Roger. CS 635 Advanced Object-Oriented Design & Programming. San Diego State University. 2001. http://www.eli.sdsu.edu/courses/spring01/cs635/notes/proxy/proxy.html#Heading1 0 Shalloway, Alan., and Trott, James R., Design Patterns Explained: A New Perspective on Object-Oriented Design, Addison-Wesley, 2002. Rising, Linda., The Patterns Handbook: Techniques, Strategies, and Applications, Cambridge university Press, 1998. UNIT-III