Skip to main content

VBA versus .NET

Bridge Pattern

A bare-bones, generic implementation of the bridge pattern, using inheritance, polymorphism, and abstraction. 

Salient Characteristic(s)

  • Decouple classes, allowing them to vary independently
  • Useful when frequent changes are made to classes

Code

namespace DesignPatterns

{
    /// <summary>
    /// The implementor: the abstract class, and concrete implementation of one side of the relation
    /// </summary> 
    public interface IBridgeAbstraction
    {
        void Build();
    }
    
    abstract class BridgeAbstraction : IBridgeAbstraction
    {
        public abstract void Build();
    }

    class ConcreteBridge1 : BridgeAbstraction
    {
        public override void Build()
        {
        }
    }

    class ConcreteBridge2 : BridgeAbstraction
    {
        public override void Build()
        {
        }
    }
    
    
    /// <summary>
    /// The abstract class, and concrete implementation of other side of the relations 
    /// </summary>
    public abstract class AbstractionBridgeSupplier
    { 
        public abstract void BuildBridge(IBridgeAbstraction bridge);
    }

    public class ConcreteBridgeSupplier : AbstractionBridgeSupplier
    {
        public override void BuildBridge(IBridgeAbstraction bridge)
        {
            bridge.Build();
        }
    }


    /// <summary>
    /// The client:  the intermediary between the two independently varying sides 
    /// </summary>
    public class ConcreteBridgeBuilder
    {
        public ConcreteBridgeBuilder()
        {
            ConcreteBridgeSupplier supplier = new ConcreteBridgeSupplier();
            supplier.BuildBridge(new ConcreteBridge1());
            supplier.BuildBridge(new ConcreteBridge2());
        }
    }
}

Comments

Popular posts from this blog

Migrating and Design Planning

I have been toying with the idea of migrating one of my sites to a better host - it was supported by Yahoo and now AAbaco - and implementing some newer technologies. Among products I have used at work or are working with peripherally, I am considering using ASP.NET MVC, Entity Framework, ReSTful API's, NoSQL, and Azure-hosted databases - it is currently a mixture of very low-end PHP, HTML5/CSS3, light Javascript, and MySQL - so I decided to write up an architectural diagram - it looks like any standard architecture, with maybe a few additional elements - to help with the planning:

James Igoe's Reviews > Thinking Architecturally

Thinking Architecturally by Nathaniel Schutta My rating: 4 of 5 stars An overview of architectural decisions, the politics and persuasion involved, and the needs to balance competing measures and attributes. A fairly easy read, but full of great suggestions, and, for many, reminders of how to handle being a senior developer or architect. View all my reviews

How do you deal with making sure your use of new technology is correct and free from code-smells, security issues, etc.? - Hashnode

Responding to How do you deal with making sure your use of new technology is correct and free from code-smells, security issues, etc.? : Issues can be dealt with in several ways. Understanding what makes high-quality, maintainable code would be first, so knowledge of best practices regarding OOP, SOLID, design patterns, API design, etc. is important. Depending on what you mean by security, best practices in those regarding transfer protocols, coding styles, validation, storage, etc. are equally something one can learn. Planning your work is useful, as a well thought out design is easier to implement, or at least will avoid future problems, than when you are just 'winging it'. Diagramming and project plans can be useful at this stage. Self-management is part of this, so using boards and epic/stories/tasks to track work is important, and there are free tools like Visual Studio Team Services (VSTS) or Trello to help. Requirements gathering will matter so documentation and c...