Skip to main content

VBA versus .NET

Facade

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 systems
  • Simplified interaction between systems and/or types
Note

  • DispatchingObservableCollection is based on ObservableCollection commonly used in Windows Presentation Foundation (WPF) applications and available from one of my other sites.
  • Some classes are not available in this example, i.e., TrackedConnections, CubeInfo, and ConfigurationList, since they are part of the larger project, and would detract his example
Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Net;
using System.Reflection;
using System.ServiceModel;
using System.Threading;

namespace DesignPatterns
{
    public interface ISubscriber
    {
        string UserId { get; set; }
        string Workstation { get; set; }
        string Title { get; set; }
        string Host { get; set; }
        string Port { get; set; }

        bool IsConnected { get; }
        TrackedConnections Tracker { get; set; }

        [OperationContract(IsOneWay = false)]
        void Attach(string userId, string workstation, string application);

        # region Methods used for Excel clients, used with delegate for status updates

        [OperationContract(IsOneWay = true)]
        void Update(IList<CubeInfo> message);

        [OperationContract(IsOneWay = false)]
        void Run();

        [OperationContract(IsOneWay = false)]
        void SendWorkbokForTracking(TrackedConnection item);

        UserConfigurationList Configuration { get; set; }

        # endregion

        # region Methods for legacy clients - single execution with return

        [OperationContract(IsOneWay = false)]
        IList<CubeInfo> GetAvailableCubeStatus();

        [OperationContract(IsOneWay = false)]
        CubeInfo GetActiveCube();

        # endregion

        # region Load Status methods - returns slices to load information

        [OperationContract(IsOneWay = false)]
        DataSet GetLoadStatusByDate(string viewDate);

        [OperationContract(IsOneWay = false)]
        DataSet GetLoadStatusBySource(string viewDate);

        [OperationContract(IsOneWay = false)]
        DataSet GetLoadStatusByRegion(string viewDate);

        # endregion
    }

    interface ISubscriberFacade
    {
        event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        DispatchingObservableCollection<CubeInfo> ActiveCubes { get; }
        DispatchingObservableCollection<CubeInfo> CubeList { get; }
        CubeInfo ActiveCube { get; }

        void Connect();
        void Detach();
        void Dispose();

        string Host { get; }
        string Port { get; }

        bool Status { get; }
        DateTime TimeStamp { get; }
        string AsString { get; }
        string ToString();
        bool UseWindowsAuthentication { get; }
    }
}

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