The IData Extension Solution
A C# Interface is an abstraction of a Software Entity that creates a Contract with the Implementing Type, a Class or a Struct.
The Interface defines the signature of a concrete Software Entity such as a Property, a Method, an Indexer or an Event.
The implementing Type has the responsibility to create the actual concrete functionality for the signature defined within the Interface.
By the Conventional definition of an Interface it has No Actual Implementation
… It is only a “Contract” between the Interface and the Implementing Class or Struct
…… to Implement the Defined Signatures within the Interface
Can an Interface have Concrete Behavior Methods that an Implementing Class or Struct Can Inherit?
The Answer is YES!!!
The System.LINQ Paradigm
Language Integrated Query, or LINQ, is a very cleaver solution for the requirement of adding a Language-based query syntax for retrieving elements from in-memory collections in C#.
The challenge that the Microsoft team faced was creating a language that was usable as an natural language query that could be extensible across all C# Types that would hold collections of data. The solution had to accomplish this without having to create the functionality on each type individually. This ruled out concrete types.
It was decided to create Extension Methods on Interfaces that all of the collection types would implement. These collections interfaces are IEnumerable<T> and IQueryable<T>.
The C# keyword this is used to add Extension Methods to Classes. It is also available to add Concrete Functionality to Interfaces
The Extended Interface
Lets take a scenario where we have two concrete Data Transfer Objects (DTO): StubData and ServicesData. The StubData type is used for Test Data for our Unit Tests and ServicesData is real-time data feeds from WCF Web Services that return the DTO Composite ServicesData.
Both of the concrete types implement a Generic IData Interface. This interface have a common Method Signature: GetData().
The GetData() method returns a Response DTO that is defined by the concrete class. The Generic T Type defines the specific Request and Response DTO Type within the Class Signature.
The IData Extension Solution
The following two tabs change content below.
I am a Principal Architect at Liquid Hub in the Philadelphia area specializing in Agile Practices as a Certified Scrum Master (CSM). I use Test Driven Development (TDD) and Acceptance Test Driven Development (ATDD) with Behavior Driven Development (BDD) as my bridge to Agile User Stories Acceptance Criteria in a Domain Driven Design (DDD) implementing true RESTful services
Latest posts by Brad Huett (see all)
- DevOps: A Bridge to Your DevOps Culture - March 25, 2016
- Embracing Test Driven Development (TDD) - March 25, 2016
- DevOps: Delivering Agile Projects - March 25, 2016