Is it better to load up a class with methods or extend member functionality in a local subclass?

Posted by Calvin Fisher on Programmers See other posts from Programmers or by Calvin Fisher
Published on 2011-03-07T19:22:45Z Indexed on 2011/03/08 8:18 UTC
Read the original article Hit count: 367

Filed under:
|
|

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.

© Programmers or respective owner

Related posts about c#

Related posts about .NET