So what pattern is this

I was working with Rob Seder on an interesting problem.  I have a 3rd party assembly that I am writing a façade over – this façade will be used by other developers in their applications.  Because of licensing, the 3rd party assembly cannot be installed on workstations.  The assembly can be installed on a WCF service that applications can then call – a façade calling another façade.

Following the ADO.NET model, we created a Connection that inherited from DBConnection and a Command that inherited from DbCommand.  My initial thought was to create two different commands that reflect the different connection methods: a WebServiceCommand and a DirectCallCommand with the individual implementations in each command’s ExecuteScaler() method.  Each command would take in a connection that that is specific to the connection type.

After some discussion, we decided to do the opposite.  We created an interface for the connections that have 1 method, Execute, and that takes in the type of command needed.

interface IFooConnection
{
    object Execute(FooCommand command);
}

The FooCommand derived from DbCommand and newed the Connection property:

image

 

We then created two connections that implement the IFooConnection interface, for example:

image

and

image

 

In the execute method, we implemented the connection-specific code.  The WebService call in the FooWebServiceConnection and the direct API calls in the FooDirectCallConnnection.

Then, we overrided the FooCommand ExecuteScaler, that calls the connection’s specific implementation:

public override object ExecuteScalar()
{
    return this.Connection.Execute(this);
}

I like this solution because it is extensible – new kinds of FooConnections come in, we just have to create specific implementation in the Execute method.  I have some questions in my head:

  • Does this follow any established design-pattern?  I re-read the GOF book this AM and could not find one that matched.
  • Is this an example of any SOLID principle?
  • Is this an example of Dependency Injection?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: