Skip to main content

VBA versus .NET

Builder

Below is a fairly straightforward 'fill-in-the-blanks' example of a Builder design pattern:

Salient Characteristic(s)

  • Defines a base type
  • Defers creation of type to derived types
Code

using System;

namespace DesignPatterns
{
    //the type of object to be built by the specific builders
    public class BuilderObject
    {
        public string Property1 = string.Empty;
        public string Property2 = string.Empty;
        public string Property3 = string.Empty;
    }

    abstract class Builder
    {
        //protected object to be built
        protected BuilderObject _Object;

        //method to return object
        public BuilderObject GetBuilder()
        {
            return _Object;
        }

        //method to create object
        public void BuildObject()
        {
            _Object = new BuilderObject();
        }

        //public abstract method(s) for building object
        //derived classes will implement
        public abstract void BuildMethod1();
        public abstract void BuildMethod2();
        public abstract void BuildMethod3();
    }

    //class 1 of n that inherits Builder class
    //and overrides each abstract method for building
    class Builder1 : Builder
    {
        public override void BuildMethod1()
        {
            //
        }
       
        public override void BuildMethod2()
        {
            //
        }

        public override void BuildMethod3()
        {
            //
        }
    }

    //class 2 of n that inherits Builder class
    //and overrides each abstract method for building
    class Builder2 : Builder
    {
        public override void BuildMethod1()
        {
            //
        }

        public override void BuildMethod2()
        {
            //
        }

        public override void BuildMethod3()
        {
            //
        }
    }

    //director class that accepts builder type (from inherited builder base type)
    class Director
    {
        private Builder _Builder;

        public Director(Builder builder)
        {
            _Builder = builder;
        }

        public Builder CreateBuilderObject()
        {
            _Builder.BuildMethod1();
            _Builder.BuildMethod2();
            _Builder.BuildMethod3();

            return _Builder;
        }
    }

    class Start
    {
        public Start()
        {
            Builder builderExample = new Builder1();
            builderExample.BuildObject();
            BuilderObject newBuilder1Object = builderExample.GetBuilder();
        }
    }
}

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

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...