Wednesday, March 4, 2015

What Does an Interface Do?

I've been knee deep in html5, web media, graphjs, and fftjs trying to fit all of that together to produce a radial graph of audio spectrum. Also been toying around with cryptographic algorithms in graphic form. Essentially, I'm creating cs-art. That is, art based on computer science.

In the meantime, I've taken on a mentee. Our project that we are undertaking is a library for analyzing server data such as running services, uptime, disk capacity, etc. While there is some degree of reinventing the wheel, we are taking a behavior driven development (BDD) approach using SpecFlow (Cucumber for .NET) as our automated user acceptance testing tool.

Currently, we have one scenario defined. In implementing the test, we created an IServer interface. Upon reflection, I think this interface is more like a facade than what an interface should be. Let me clarify.

The current interface definition contains one method - GetServices which returns an IEnumerable of WindowsServices (our own DTO). Perhaps this contract should be more specific to what we need to do rather than what the object is. In this way we will be more align with the interface segregation (ISP).

Perhaps we have an interface called IWindowsServiceReader.

This definition makes clear the intent of the consumer, interfaces are all about the consumer. The implementation can be defined in one or many classes, and one class can implement several interfaces.

So, if we have several interfaces that read server info, we may have a single class called WindowsServer2012 that implements IWindowsServiveReader, IWindowsTaskReader, IDiskInfoReader, etc. ISP at its finest!

No comments:

Post a Comment