Post

Log inSign up

Post

Log inSign up

Nemanja Rogic on X: "Bridge is a structural design pattern that lets you split a large class into two separate hierarchies - abstraction and implementation, which can be developed independently of each other. Brief introduction + demo code ↓ #designpatterns #dotnet #csharp #coding #programming"

@rogic_nemanja
Nemanja Rogic
@rogic_nemanja
Bridge is a structural design pattern that lets you split a large class into two separate hierarchies - abstraction and implementation, which can be developed independently of each other. Brief introduction + demo code ↓ #designpatterns #dotnet #csharp #coding #programming
10:05 AM · Feb 27, 2021·
1

Log in or sign up for X

See what’s happening and join the conversation

Continue with phone
or
Log in with username or email

Relevant people

Avatar
Nemanja Rogic@rogic_nemanjaFollow
Senior Software Engineer @Microsoft • Passionate about software craftsmanship, shipping reliable products, and tackling challenging problems

Trending now

Terms·Privacy·Cookies·Accessibility·US TIDA·Ads Info·© 2026 X Corp.
  • @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Bridge is a structural design pattern that lets you split a large class into two separate hierarchies - abstraction and implementation, which can be developed independently of each other. Brief introduction + demo code ↓ #designpatterns #dotnet #csharp #coding #programming
    10:05 AM · Feb 27, 2021·
    1
  • @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Feb 27, 2021
    In this example, we will work with various kinds of documents with the support to format and represent each document independently. First, we will define IFormatter interface as well as a few options for document formatting.
    1
    @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Feb 27, 2021
    Formatters represent the implementation dimension of Bridge pattern. Next, we need to tackle the abstraction part, which will be a document in this case.
    1
    @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Feb 27, 2021
    How to use this code?
    1
    @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Feb 27, 2021
    The "abstraction" defines the contract for the control part of the two-class hierarchies. It maintains a reference to an object of the "implementation" hierarchy and usually delegates all of the real work to this object.
    1
    @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Feb 27, 2021
    The "implementation" interface provides only primitive operations, while the abstraction defines higher-level operations based on those primitives.
    1
    @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Feb 27, 2021
    Consider a TV device that acts as the implementation, whereas the remote acts as the abstraction. The device defines a primitive operation to set volume, whereas remotes can make users life easier and offer the possibility to mute the device (mute will internally call set volume)
    1
    @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Feb 27, 2021
    Full implementation of a device/remote example, as well as an example that shows how to use enums to achieve bridge design pattern, can be found on
    GitHub - nemanjarogic/DesignPatternsLibrary: A comprehensive design patterns library implemented in...
    From github.com
    1
    @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Feb 27, 2021
    Use the Bridge pattern when you want to divide and organize a monolithic class that has several variants of some functionality. Use this pattern when you need to extend a class in several orthogonal (independent) dimensions or if you need to switch implementations at runtime..
    1
    @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Feb 27, 2021
    + The client code works with high-level abstractions. It isn’t exposed to the platform details. Abstraction and the implementation are developed independently and the client code can access only the abstraction part without being concerned about the Implementation part.
    1
    @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Feb 27, 2021
    + You can introduce new abstractions and implementations independently from each other (Open/Closed Principle) + It increases the loose coupling between abstraction and its implementation
    1
    @rogic_nemanja
    Nemanja Rogic
    @rogic_nemanja
    Feb 27, 2021
    + You can focus on high-level logic in the abstraction and on platform details in the implementation (Single Responsibility Principle) - You might make the code more complicated by applying the pattern to a highly cohesive class.