Download presentation
Presentation is loading. Please wait.
1
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
2
Agenda Intent & Motivation Structure Applicability Consequences
Known Uses Related Patterns References UNIT-III
3
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
4
Motivation L1 1 UNIT-III
5
L1 Structure (Class) UNIT-III
6
L1 Structure (Object) UNIT-III
7
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
8
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
9
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
10
L1 Pluggable Adapters implemented with abstract operations UNIT-III
11
L1 Pluggable Adapters implemented with delegate objects UNIT-III
12
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
13
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
14
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
15
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
16
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
17
Adapter (cont.) L1 class NewTime { public: int GetTime() {
return m_oldtime.get_time() * ; } private: OldTime m_oldtime; }; UNIT-III
18
L2 The Bridge Pattern UNIT-III
19
Overview Intent Also Known As Motivation Participants Structure
Applicability Benefits Drawbacks Related Pattern I UNIT-III
20
BRIDGE (Object Structural)
Intent: Decouple as abstraction from its implementation so that the two can vary independently. Also Known As: Handle/Body UNIT-III
21
L2 Motivation Entry oracleDBEntry FilesysEntry UNIT-III
22
Motivation Entry Appointment OracleDBTask Task OracleDBApp.
FilesysApp. FilesysTask UNIT-III
23
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
24
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
25
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
26
Structure L2 impl RefinedAbstraction ConcreteImplementerA
ConcreteImplementerB Implementer OperationImp() Client Abstraction impl UNIT-III
27
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
28
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
29
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
30
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
31
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
32
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
33
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
34
L3 UNIT-III
35
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
36
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
37
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
38
BRIDGE (Object Structural)
Intent: Decouple as abstraction from its implementation so that the two can vary independently. Also Known As: Handle/Body UNIT-III
39
L4 Motivation Entry oracleDBEntry FilesysEntry UNIT-III
40
Motivation Entry Appointment OracleDBTask Task OracleDBApp.
FilesysApp. FilesysTask UNIT-III
41
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
42
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
43
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
44
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
45
L7 References Becker, Dan. Design networked applications in RMI using the Adapter design pattern. JavaWorld Magazine, May /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 fall/tutorials/10/tutorial10.html Whitney, Roger. CS 635 Advanced Object-Oriented Design & Programming. San Diego State University 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.