Daily Archives: April 14, 2012

Data Access Layer – Reusing the Abstract Interface

Lets take some time to examine the re-usability of the abstract interface we implemented in the previous post. This time we will implement the IArtWorldCollection interface, to create a collection of works of art, along with artists who created them. Once again here is a code snippet of the interface;

Now, here is the second implementation of this interface, in a class I named ArtWorldCollectionArtPiece. The purpose of this class, is to create a collection of works of art, found in the World of Art domain;

This implementation is essentially the same as the ArtWorldCollectionArtist class, except for two very import elements. Notice that in this implementation, I replaced the generic object type of “T” with the art piece object from the World of Art Domain, which is defined in the ArtWorldObjects class library. This object replacement occurred in two places, one is at the beginning of the class, where the implementation of the IArtWorldCollection interface is declared. The second is in the ArtWorldCollection property, which is defined as a type of Generic List Class.

This second implementation demonstrates just how re-usable the IArtWorldCollection interface is. This high level of reuse is achieved by coding the interface based on a generic type “T”. For more information on generic types in C#, see An introduction to C# Generics and Generic Interfaces C# Programming Guide. The IArtWorldCollection interface, can be reused over and over again, to generate many different collections of objects found in the world of art domain. These are enumerable collections of objects, which can be consumed by many different kinds of software clients.

In my next post, we will examine the GetArtCollectionData() method of the ArtWorldCollectionArtPiece class in more detail, and wrap up our discussion on separation of concerns,the entity framework, and the data access layer of our application architecture.