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

Do Algorithms Make You a Better Developer?

Responding to a question on HashNode, Developers who practise algorithms are better at software development than people who just do development. Is it true? , I wrote the following: My feeling is that algorithms help make one a better programmer, but that is likely true of many coding concepts. I did not have algorithms as an undergraduate, so my knowledge is acquired through reading and practice, but after reading and applying Algorithm's in a Nutshell, I felt the quality of my work improved. That said, my development work increased more after understanding Design Patterns, or after consuming books on database design.  Since many types of knowledge improve developing and architecting abilities, one has to consider how it helps and to what degree. Algorithms are coding-in-the-small, often narrowly focused solutions, but which can have a great impact at scale. For many applications, a focus on algorithms would be overkill as data sets and requirements do not require it. In this ...

VBA versus .NET

I was recently messaged by someone on LinkedIn, and since my response seemed full enough, I thought I'd share. Question I see that you also program in VBA but you have made the jump to .NET. Unfortunately, I have found C#/Excel coding to be quite slow and just wanted to hear about your experiences. Responses Slow? It depends on what you mean. Honest, I have had to make the pitch when building apps that it should be in .NET rather than VBA for speed. One particular app had a form that needed to fill about 20 dropdowns on load, so using async operations was essential. That same app, while executing one SQL statement in the foreground, also executed 2 background statements that filled panels. It wouldn't have performed well if done in VBA. If you mean that it takes longer, then yes, but that is a necessity for good code anyway. If you only need a local operation, non-threaded, that doesn't need to be used across the enterprise, VBA can make sense, but with .NET comes n...

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