Wrapping a DataSet
Imagine that you want to provide a certain interface for your data container, but you want to do it with as little up-front work as possible. Wrapping a generic container datatype is one neat solution to that problem. The datatype I have chosen to use in the following discussion is an untyped DataSet. Thanks to that, I get all the functionality of the untyped DataSet for free, while still maintaining a very small interface so that I can change the wrapped datatype when I want to, without affecting all the consumer code.
Other possible options are to wrap, for example, an XML DOM, an Array, an ArrayList, and so on.
In Figure 1, you can see a sample Order class that wraps an untyped DataSet.
Figure 1 Class model of a wrapped DataSet.
In the Order class, there are properties for getting the ID of the Order, the CustomerId, and the OrderDate. To get to the data of a specific order line, you need to specify an index as a parameter to the property that you want to inspect.
The design of this Order class is simplistic, just for getting the job done and so that I have something for my tests. If you want to go this route, you should, of course, spend some more time designing the class.
Then it's very easy to add custom functionality that will live together with the data. I have added only a Validate() method in Figure 1, but when you start adding custom behavior this solution will take off. (That also goes for custom behavior in the property methods.)