Skip to content

dotnet-simformsolutions/bridge-design-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bridge Design Pattern

  • As per the Gang of Four definitions, the Bridge Design Pattern “Decouples an abstraction from its implementation so that the two can vary independently“.

  • In the Bridge Design Pattern, there are 2 parts. The first part is the Abstraction and the second part is the Implementation. The Bridge Design Pattern allows both Abstraction and Implementation to be developed independently and the client code can only access the Abstraction part without being concerned about the Implementation part.

When do we need to use Bridge Design Pattern in C# Real-Time Applications?

  • We want to hide the implementation details from the client.
  • We want the selection or switching of the implementation to be at runtime rather than design time.
  • We want both the abstraction and implementation classes to be extensible by the subclasses.
  • We want to avoid a tight coupling binding between an abstraction and its implementation.
  • The changes in the implementation of an abstraction should have no impact on clients.

Let's implement the Bridge Pattern

  • We have a DrawAPI interface which is acting as a bridge implementer and concrete classes RedCircle, GreenCircle implementing the DrawAPI interface. Shape is an abstract class and will use object of DrawAPI. BridgePatternDemo, our demo class will use Shape class to draw different colored circle.

    image

  • Create bridge implementer interface.

    image

  • Create concrete bridge implementer classes implementing the IDrawService interface.

    image

    image

  • Create an abstract class Shape using the IDrawService interface.

    image

  • Create concrete class implementing the Shape interface.

    image

  • Use the Shape and IDrawService classes to draw different colored circles.

    image

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages