A Data Transfer Object (DTO) is one that can be used to pass
data across the layers of an application. In this article I will demonstrate
how we can implement a generic Data Transfer Object that can be used in lieu of
DataSet, DataTable or even Custom Business Entity instances to transfer data
through the layers of an application.
This implementation of the DTO comprises of a generic
Business Entity that can be a DataSet instance, a DataTable instance, a Custom Business
Entity instance, etc. as the data container. The instances of the DTO are in turn
stored in a DTO Register, which actually is a hash table that stores the DTO
instances as key - value pairs, the key being the hash code of the DTO instance
and the value being the DTO instance itself. This hash code is actually used to
pass data across the layers of the application. Such a design promotes loose
coupling, flexibility and re-usability in your architecture. I have used generics
in this design to use any business entity instance as a data container.