Object Design: How to Organize/Structure a "Collection Class"

Posted by CrimsonX on Stack Overflow See other posts from Stack Overflow or by CrimsonX
Published on 2010-05-25T23:35:22Z Indexed on 2010/05/25 23:41 UTC
Read the original article Hit count: 257

Filed under:
|
|

I'm currently struggling to understand how I should organize/structure a class which I have already created. The class does the following:

  1. As its input in the constructor, it takes a collection of logs
  2. In the constructor it validates and filters the logs through a series of algorithms implementing my business logic
  3. After all filtering and validation is complete, it returns a collection (a List) of the valid and filtered logs which can be presented to the user graphically in a UI.

Here is some simplified code describing what I'm doing:

class FilteredCollection
{
  public FilteredCollection( SpecialArray<MyLog> myLog)
  {   
  // validate inputs
  // filter and validate logs in collection
  // in end, FilteredLogs is ready for access
  }
  Public List<MyLog> FilteredLogs{ get; private set;}

}

However, in order to access this collection, I have to do the following:

var filteredCollection = new FilteredCollection( secialArrayInput );
//Example of accessing data
filteredCollection.FilteredLogs[5].MyLogData;

Other key pieces of input:

  1. I foresee only one of these filtered collections existing in the application (therefore should I make it a static class? Or perhaps a singleton?)
  2. Testability and flexibility in creation of the object is important (Perhaps therefore I should keep this an instanced class for testability?)
  3. I'd prefer to simplify the dereferencing of the logs if at all possible, as the actual variable names are quite long and it takes some 60-80 characters to just get to the actual data.
  4. My attempt in keeping this class simple is that the only purpose of the class is to create this collection of validated data.

I know that there may be no "perfect" solution here, but I'm really trying to improve my skills with this design and I would greatly appreciate advice to do that. Thanks in advance.

© Stack Overflow or respective owner

Related posts about c#

Related posts about collection