Simplicity over Complexity

2 minute read

Today I was working on a reporting feature for an ASP.NET application I develop/manage at work and came across an interesting design decision.  Per the request of the users of the application, I am adding the ability to export reports to an excel file but I only wanted to display the basic information for each record that will be exported. The library that I am using to export the data is the EPPlus library which makes it really easy to export data to Excel 2007/2010.  All you need to do is pass an object that implements IEnumerable and the library does the rest! the only problem with this is that it’ll show every public property of the object!  I needed to come up with a way to display only the import for the report.

At first I though of creating a custom object that will then be used to load up a List collection and pass this along to the LoadFromCollection(IEnumerable) method.  But I took a step back and thought about the implications of such a decision.   I didn’t want to introduce another class into the program if it’s only going to be used in one location. Additionally, another class meant another object to manage and maintain in the application which is not what I want to do for the application which just keep growing and growing in both Lines of Code and complexity!  So I came up with a simple solution of using a DataSet object and return this instead of a List.

The decision to return a DataSet object turned out to be the best one as this was not only the simplest solution, but also it turned out to be more flexible than I had imagined!  Being able to make changes to the SQL Query on the fly to get only the data I want is great! I would not have been able to do this with a custom object which makes my job as the developer that much easier!  Below is the method signature I ended up writing:

 /// <summary>
 /// This method returns the specified recognition types that were created within the
 /// specified date range. Note: this method returns a data set object as the results
 /// from this method will be used to display data in an excel 2007/2010 worksheet.
 /// </summary>
 /// <param name="recognitionTypeID"></param>
 /// <param name="fromDate"></param>
 /// <param name="toDate"></param>
 /// <returns></returns>
public DataSet GetRecogntionsDataSetByDate(int, string, string)

Notice how I used the word DataSet in the name of the method and also added a comment to remind me that this will be used in an excel worksheet.  I always strive to write code that is simple and easy to maintain and this solution adheres to this rule of mine!

Leave a comment