SlideShare une entreprise Scribd logo
1  sur  14
Design Pattern
Bridge Pattern
A Structural design pattern




                              Copyright © Astha
The Problem
Suppose a task has been given of writing a program that will draw rectangles
with either of two drawing programs. It also have been told that when
instantiate a rectangle, it will know whether it should use drawing program 1
(DP1) or drawing program 2 (DP2).

The rectangles are defined as two pairs of points, as represented in the
following figure. The differences between the drawing programs are
summarized
in Table below.
                                                     X2, Y2




           X1, Y1
                                                 Copyright © Astha
The Problem
                      DP1                   DP2
 Used to draw a       draw_a_line( x1,      drawline( x1, x2,
 line                 y1, x2, y2)           y1, y2)
 Used to draw a       draw_a_circle( x, y, drawcircle( x, y, r)
 circle               r)


we don’t want the code that draws the rectangles to worry about what
type of drawing program it should use. It occurs to me that because the
rectangles are told what drawing program to use when instantiated, I can
have two different kinds of rectangle objects: one that uses DP1 and one
that uses DP2. Each would have a draw method but would implement it
differently.




                                             Copyright © Astha
The Problem




              Copyright © Astha
The Problem
A straightforward approach: implementing two shapes and two
drawing programs.




                                       Copyright © Astha
The Problem
Bridge in Action




                   Copyright © Astha
Intent
Decouple an abstraction from its implementation so that the two can vary
independently.




                                              Copyright © Astha
Applicability
Use the Bridge pattern when
 you want to avoid a permanent binding between an abstraction and its
implementation. This might be the
case, for example, when the implementation must be selected or switched at
run-time.
 both the abstractions and their implementations should be extensible by
subclassing. In this case, the Bridge
pattern lets you combine the different abstractions and implementations and
extend them independently.
 changes in the implementation of an abstraction should have no impact on
clients; that is, their code should
not have to be recompiled.




                                               Copyright © Astha
Structure




            Copyright © Astha
Participants
• Abstraction (Window)
    o defines the abstraction's interface.
    o maintains a reference to an object of type Implementor.
• RefinedAbstraction (IconWindow)
    o Extends the interface defined by Abstraction.
• Implementor (WindowImp)
    o defines the interface for implementation classes. This interface doesn't
    have to correspond exactly to Abstraction's interface; in fact the two
    interfaces can be quite different. Typically the Implementor interface
    provides only primitive operations, and Abstraction defines higher-level
    operations based on these primitives.
• ConcreteImplementor (XWindowImp, PMWindowImp)
    o implements the Implementor interface and defines its concrete
    implementation.




                                                Copyright © Astha
Collaborations
• Abstraction forwards client requests to its Implementor object.




                                               Copyright © Astha
Consequences
   Decoupling interface and implementation. An implementation is not bound
    permanently to an interface. The implementation of an abstraction can be
    configured at run-time. It's even possible for an object to change its
    implementation at run-time.
   Improved extensibility. You can extend the Abstraction and Implementor
    hierarchies independently.
   Hiding implementation details from clients. You can shield clients from
    implementation details, like the sharing of Implementor objects and the
    accompanying reference count mechanism (if any).




                                                Copyright © Astha
Implementation
1. Only one Implementor. In situations where there's only one implementation,
   creating an abstract Implementor class isn't necessary. This is a degenerate
   case of the Bridge pattern; there's a one-to-one relationship between
   Abstraction and Implementor. Nevertheless, this separation is still useful
   when a change in the implementation of a class must not affect its existing
   clients—that is, they shouldn't have to be recompiled, just relinked.
2. Creating the right Implementor object. How, when, and where do you decide
   which Implementor class to instantiate when there's more than one?




                                                 Copyright © Astha
Assignment
A document viewer has been made for an enterprise solution (desktop
application), which supports viewing of some specific types of documents. The
supporting types are HTML, Microsoft Word and Microsoft Excel.

Underneath, the document viewer uses an abstract interface of the document
which contains methods to show the document in the viewer.

Now the enterprise application is going to have a web solution where there
would be another document viewer (different in several aspects from the
existing one) with the same functionalities as it is now in the desktop version.

Use the Bridge pattern to solve the problem in such a way that new document
types can be easily incorporated into the system and new type of document
viewer can also be incorporated.




                                                 Copyright © Astha

Contenu connexe

Tendances

Design Patterns
Design PatternsDesign Patterns
Design Patterns
soms_1
 

Tendances (20)

Design patterns
Design patternsDesign patterns
Design patterns
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Bridge pattern for Dummies
Bridge pattern for DummiesBridge pattern for Dummies
Bridge pattern for Dummies
 
Design Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator PatternDesign Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator Pattern
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Facade Pattern
Facade PatternFacade Pattern
Facade Pattern
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Decorator Pattern
Decorator PatternDecorator Pattern
Decorator Pattern
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design Pattern
 
Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion Principle
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Deployment Diagram
Deployment DiagramDeployment Diagram
Deployment Diagram
 
Prototype_pattern
Prototype_patternPrototype_pattern
Prototype_pattern
 

En vedette (13)

Bridge Pattern Derek Weeks
Bridge Pattern   Derek WeeksBridge Pattern   Derek Weeks
Bridge Pattern Derek Weeks
 
Bridge Pattern
Bridge PatternBridge Pattern
Bridge Pattern
 
20120420 - Design pattern bridge
20120420 - Design pattern bridge20120420 - Design pattern bridge
20120420 - Design pattern bridge
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
 
Command Pattern
Command PatternCommand Pattern
Command Pattern
 
Command pattern
Command patternCommand pattern
Command pattern
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Structural Design pattern - Adapter
Structural Design pattern - AdapterStructural Design pattern - Adapter
Structural Design pattern - Adapter
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Descriptive statistics
Descriptive statisticsDescriptive statistics
Descriptive statistics
 
Implementing the Adapter Design Pattern
Implementing the Adapter Design PatternImplementing the Adapter Design Pattern
Implementing the Adapter Design Pattern
 
Security and Integrity of Data
Security and Integrity of DataSecurity and Integrity of Data
Security and Integrity of Data
 

Similaire à Bridge pattern

Design Patterns By Sisimon Soman
Design Patterns By Sisimon SomanDesign Patterns By Sisimon Soman
Design Patterns By Sisimon Soman
Sisimon Soman
 
Utilizing Layers in AutoCAD Prototype Package
Utilizing Layers in AutoCAD Prototype PackageUtilizing Layers in AutoCAD Prototype Package
Utilizing Layers in AutoCAD Prototype Package
Brian Mitchell
 
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISESoftware Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
sreeja_rajesh
 

Similaire à Bridge pattern (20)

Design Patterns By Sisimon Soman
Design Patterns By Sisimon SomanDesign Patterns By Sisimon Soman
Design Patterns By Sisimon Soman
 
How to design an application correctly ?
How to design an application correctly ?How to design an application correctly ?
How to design an application correctly ?
 
EMC Documentum xCP 2.0 Design Patterns
EMC Documentum xCP 2.0 Design PatternsEMC Documentum xCP 2.0 Design Patterns
EMC Documentum xCP 2.0 Design Patterns
 
Ch08lect2 ud
Ch08lect2 udCh08lect2 ud
Ch08lect2 ud
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
 
Utilizing Layers in AutoCAD Prototype Package
Utilizing Layers in AutoCAD Prototype PackageUtilizing Layers in AutoCAD Prototype Package
Utilizing Layers in AutoCAD Prototype Package
 
Technical-design-for-Angular-apps.pdf
Technical-design-for-Angular-apps.pdfTechnical-design-for-Angular-apps.pdf
Technical-design-for-Angular-apps.pdf
 
React Workshop
React WorkshopReact Workshop
React Workshop
 
NX training Report
NX training ReportNX training Report
NX training Report
 
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISESoftware Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
 
Polyline download and visualization over terrain models
Polyline download and visualization over terrain modelsPolyline download and visualization over terrain models
Polyline download and visualization over terrain models
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 
Programming Without Coding Technology (PWCT) Features - Programming Paradigm
Programming Without Coding Technology (PWCT) Features - Programming ParadigmProgramming Without Coding Technology (PWCT) Features - Programming Paradigm
Programming Without Coding Technology (PWCT) Features - Programming Paradigm
 
The Big Picture - Integrating Buzzwords
The Big Picture - Integrating BuzzwordsThe Big Picture - Integrating Buzzwords
The Big Picture - Integrating Buzzwords
 
Q Cad Presentation
Q Cad PresentationQ Cad Presentation
Q Cad Presentation
 
INTERSHIP PPT.pptx
INTERSHIP PPT.pptxINTERSHIP PPT.pptx
INTERSHIP PPT.pptx
 
Presentation on
Presentation on Presentation on
Presentation on
 
Presentation
Presentation Presentation
Presentation
 
A Uniform Specification Of Mixed Reality Interface Components
A Uniform Specification Of Mixed Reality Interface ComponentsA Uniform Specification Of Mixed Reality Interface Components
A Uniform Specification Of Mixed Reality Interface Components
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 

Plus de Shakil Ahmed (15)

Algorithm
AlgorithmAlgorithm
Algorithm
 
B-tree & R-tree
B-tree & R-treeB-tree & R-tree
B-tree & R-tree
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structure
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Mediator pattern
Mediator patternMediator pattern
Mediator pattern
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
iOS 5
iOS 5iOS 5
iOS 5
 
Ios development
Ios developmentIos development
Ios development
 
Graph
GraphGraph
Graph
 
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestor
 
Segment tree
Segment treeSegment tree
Segment tree
 
Tree & bst
Tree & bstTree & bst
Tree & bst
 
Trie tree
Trie treeTrie tree
Trie tree
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search Techniques
 

Dernier

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Dernier (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

Bridge pattern

  • 1. Design Pattern Bridge Pattern A Structural design pattern Copyright © Astha
  • 2. The Problem Suppose a task has been given of writing a program that will draw rectangles with either of two drawing programs. It also have been told that when instantiate a rectangle, it will know whether it should use drawing program 1 (DP1) or drawing program 2 (DP2). The rectangles are defined as two pairs of points, as represented in the following figure. The differences between the drawing programs are summarized in Table below. X2, Y2 X1, Y1 Copyright © Astha
  • 3. The Problem DP1 DP2 Used to draw a draw_a_line( x1, drawline( x1, x2, line y1, x2, y2) y1, y2) Used to draw a draw_a_circle( x, y, drawcircle( x, y, r) circle r) we don’t want the code that draws the rectangles to worry about what type of drawing program it should use. It occurs to me that because the rectangles are told what drawing program to use when instantiated, I can have two different kinds of rectangle objects: one that uses DP1 and one that uses DP2. Each would have a draw method but would implement it differently. Copyright © Astha
  • 4. The Problem Copyright © Astha
  • 5. The Problem A straightforward approach: implementing two shapes and two drawing programs. Copyright © Astha
  • 6. The Problem Bridge in Action Copyright © Astha
  • 7. Intent Decouple an abstraction from its implementation so that the two can vary independently. Copyright © Astha
  • 8. Applicability Use the Bridge pattern when  you want to avoid a permanent binding between an abstraction and its implementation. This might be the case, for example, when the implementation must be selected or switched at run-time.  both the abstractions and their implementations should be extensible by subclassing. In this case, the Bridge pattern lets you combine the different abstractions and implementations and extend them independently.  changes in the implementation of an abstraction should have no impact on clients; that is, their code should not have to be recompiled. Copyright © Astha
  • 9. Structure Copyright © Astha
  • 10. Participants • Abstraction (Window) o defines the abstraction's interface. o maintains a reference to an object of type Implementor. • RefinedAbstraction (IconWindow) o Extends the interface defined by Abstraction. • Implementor (WindowImp) o defines the interface for implementation classes. This interface doesn't have to correspond exactly to Abstraction's interface; in fact the two interfaces can be quite different. Typically the Implementor interface provides only primitive operations, and Abstraction defines higher-level operations based on these primitives. • ConcreteImplementor (XWindowImp, PMWindowImp) o implements the Implementor interface and defines its concrete implementation. Copyright © Astha
  • 11. Collaborations • Abstraction forwards client requests to its Implementor object. Copyright © Astha
  • 12. Consequences  Decoupling interface and implementation. An implementation is not bound permanently to an interface. The implementation of an abstraction can be configured at run-time. It's even possible for an object to change its implementation at run-time.  Improved extensibility. You can extend the Abstraction and Implementor hierarchies independently.  Hiding implementation details from clients. You can shield clients from implementation details, like the sharing of Implementor objects and the accompanying reference count mechanism (if any). Copyright © Astha
  • 13. Implementation 1. Only one Implementor. In situations where there's only one implementation, creating an abstract Implementor class isn't necessary. This is a degenerate case of the Bridge pattern; there's a one-to-one relationship between Abstraction and Implementor. Nevertheless, this separation is still useful when a change in the implementation of a class must not affect its existing clients—that is, they shouldn't have to be recompiled, just relinked. 2. Creating the right Implementor object. How, when, and where do you decide which Implementor class to instantiate when there's more than one? Copyright © Astha
  • 14. Assignment A document viewer has been made for an enterprise solution (desktop application), which supports viewing of some specific types of documents. The supporting types are HTML, Microsoft Word and Microsoft Excel. Underneath, the document viewer uses an abstract interface of the document which contains methods to show the document in the viewer. Now the enterprise application is going to have a web solution where there would be another document viewer (different in several aspects from the existing one) with the same functionalities as it is now in the desktop version. Use the Bridge pattern to solve the problem in such a way that new document types can be easily incorporated into the system and new type of document viewer can also be incorporated. Copyright © Astha