Skip to main content


Showing posts from August, 2012

Abstract Cat Factory (Amusemet)

A friend amusingly posted on Facebook a retro photograph of four (4) 'designers' around a cat, with the caption alluding to designing hats for cats, and so I decided to make, somewhat incongruously, an abstract cat factory, which varies by the location of the cat..  

Salient Characteristic(s)
Classes derived from abstract typesClass creates derived (concrete) classes based on type requiredCode

namespace DesignPatterns
    public enum Location

    public enum Amusements

    public abstract class Feline
        public abstract Feline HereKittyKitty();

    public class Cat : Feline
        private Location _Location;
        private Feline _Cat = null;
        private Amusements _Amusement;
        public Cat(Location location)
            _Location = location;

        public override Feline HereKittyKitty()
            switch (_…

Adapter or Wrapper

This is code possible through .NET, in that it bridges across to COM for automation in VBA.  This concept can be extended to work for many other COM-based applications.  This code allows the add-in to expose internal .NET-coded procedures to Excel COM, extending the use of the .NET code.

Salient Characteristic(s)

Handle interface between different, incompatible systemsThe interface is required because COM is interface-basedOther code elements are required for this to work properlyRegistering the DLLCreating the AdapterForVBA class on startupCode

using System;
using System.Runtime.InteropServices;

namespace DesignPatterns
    /// <summary>
    /// Interace to expose VSTO/COM obects for COM and Excel
    /// Used by class below
    /// </summary>
    public interface IAdapterForVba
        //signatures for methods acessible to VBA go here


This is derived from actual code of mine, and elements of this sample combine the Facade pattern with the Publisher (Observer) pattern.  The primary class, based on the ISubscriber interface, is fairly complicated to use, requiring delegates, threading, and asynchronous callbacks.  The facade, based on ISubscriberFacade, encapsulates all the methods required to work with the Windows Communication Foundation (WCF) service , handling threading, delegate creation, and asynchronous callbacks internally, so that that the clients only need to create the object.  I wrote the encapsulating client to ease the adoption of the WCF service for legacy clients, seeing that the code complexity was likely a hurdle.

Salient Characteristic(s)

Reduces or hides complexities to other clients or systemsSimplified interaction between systems and/or typesNote

DispatchingObservableCollection is based on ObservableCollection commonly used in Windows Presentation Foundation (WPF) applications and available from on…