Presentation is loading. Please wait.

Presentation is loading. Please wait.

Adaptor Bridge Composite UNIT-IV1 Repeated key points for Structural Patterns (Intent, Motivation, Also Known As…) Code Examples Reference 1 2 3 4 5 6.

Similar presentations


Presentation on theme: "Adaptor Bridge Composite UNIT-IV1 Repeated key points for Structural Patterns (Intent, Motivation, Also Known As…) Code Examples Reference 1 2 3 4 5 6."— Presentation transcript:

1 Adaptor Bridge Composite UNIT-IV1 Repeated key points for Structural Patterns (Intent, Motivation, Also Known As…) Code Examples Reference 1 2 3 4 5 6 7 S. No TOPICPPT Slides L13 – 18 L219 – 31 L332 – 37 L438 – 40 L541 – 42 L643 – 44 L745 – 45

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

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

4 UNIT-IV4 Motivation 1 1 L1

5 UNIT-IV5 Structure (Class) L1

6 UNIT-IV6 Structure (Object) L1

7 UNIT-IV7 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) L1

8 UNIT-IV8 Class Adapter Pattern Pros – 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 L1

9 UNIT-IV9 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 L1

10 UNIT-IV10 Pluggable Adapters implemented with abstract operations L1

11 UNIT-IV11 Pluggable Adapters implemented with delegate objects L1

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

13 UNIT-IV13 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) L1

14 UNIT-IV14 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. L1

15 UNIT-IV15 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 L1

16 UNIT-IV16 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 L1

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

18 UNIT-IV18 The Bridge Pattern L2

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

20  Intent: Decouple as abstraction from its implementation so that the two can vary independently.  Also Known As: Handle/Body UNIT-IV20 L2

21 UNIT-IV21 Motivation Entry oracleDBEntryFilesysEntry L2

22 UNIT-IV22 Motivation Entry Appointment OracleDBTask Task OracleDBApp.FilesysApp.FilesysTask L2

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

24 UNIT-IV24 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 L2

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

26 UNIT-IV26 Structure RefinedAbstractionConcreteImplementerA ConcreteImplementerB Implementer OperationImp() Client Abstraction impl L2

27 UNIT-IV27 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. L2

28 UNIT-IV28 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. L2

29 UNIT-IV29 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 L2

30 UNIT-IV30 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. L2

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

32 UNIT-IV32 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 L2

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

34 UNIT-IV34 L3

35 UNIT-IV35 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. L3

36 UNIT-IV36 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. L3

37 UNIT-IV37 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. L3

38 UNIT-IV38 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. L7


Download ppt "Adaptor Bridge Composite UNIT-IV1 Repeated key points for Structural Patterns (Intent, Motivation, Also Known As…) Code Examples Reference 1 2 3 4 5 6."

Similar presentations


Ads by Google