Is it better to load up a class with methods or extend member functionality in a local subclass?
- by Calvin Fisher
Which is better? Class #1:
public class SearchClass
{
public SearchClass (string ProgramName)
{ /* Searches LocalFile objects, handles exceptions, and puts results into m_Results. */ }
DateTime TimeExecuted;
bool OperationSuccessful;
protected List<LocalFile> m_Results;
public ReadOnlyCollection<LocalFile> Results
{
get { return new ReadOnlyCollection<LocalFile>(m_Results); }
}
#region Results Filters
public DateTime OldestFileModified
{
get { /* Does what it says. */ }
}
public ReadOnlyCollection<LocalFile> ResultsWithoutProcessFiles()
{
return new ReadOnlyCollection<LocalFile> ((from x in m_Results
where x.FileTypeID != FileTypeIDs.ProcessFile
select x).ToList());
}
#endregion
}
Or class #2:
public class SearchClass
{
public SearchClass (string ProgramName)
{ /* Searches LocalFile objects, handles exceptions, and puts results into m_Results. */ }
DateTime TimeExecuted;
bool OperationSuccessful;
protected List<LocalFile> m_Results;
public ReadOnlyCollection<LocalFile> Results
{
get { return new ReadOnlyCollection<LocalFile>(m_Results); }
}
public class SearchResults : ReadOnlyCollection<LocalFile>
{
public SearchResults(IList<LocalFile> iList) : base(iList) { }
#region Results Filters
public DateTime OldestFileModified
{
get { /* Does what it says. */ }
}
public ReadOnlyCollection<LocalFile> ResultsWithoutProcessFiles()
{
return new ReadOnlyCollection<LocalFile> ((from x in this
where x.FileTypeID != FileTypeIDs.ProcessFile
select x).ToList());
}
#endregion
}
}
...with the implication that OperationSuccessful is accompanied by a number of more interesting properties on how the operation went, and OldestFileModified and ResultsWithoutProcessFiles() also have several more siblings in the Results Filters section.