KommerszUnicum
KommerszUnicum

Reputation: 23

Valid class hierarchy?

Does the following class hierarchy valid for TDD? I have two related class hierarchies and I need to use one type of Info object in each creator. Do you know common pattern to do this better (maybe with generics)? Is this testable?

namespace ClassTest
{
    interface IProjectInfo
    {
        void Info1();
        void Info2();
    }

    class ProjectAInfo : IProjectInfo
    {
        public ProjectAInfo(string projectAData)
        {
            ProjectAData = projectAData;
        }

        public string ProjectAData { get; private set; }

        public void Info1() { }
        public void Info2() { }
    }

    class ProjectBInfo : IProjectInfo
    {
        public ProjectBInfo(string projectBData)
        {
            ProjectBData = projectBData;
        }

        public string ProjectBData { get; private set; }

        public void Info1() { }
        public void Info2() { }
    }

    interface IProjectCreator
    {
        void Create1();
        void Create2();
    }

    class ProjectACreator : IProjectCreator
    {
        public ProjectACreator(ProjectAInfo projectAInfo)
        {
            ProjectAInfo = projectAInfo;
        }

        public ProjectAInfo ProjectAInfo { get; private set; }

        public void Create1() { }
        public void Create2() { }
    }

    class ProjectBCreator : IProjectCreator
    {
        public ProjectBCreator(ProjectBInfo projectBInfo)
        {
            ProjectBInfo = projectBInfo;
        }

        public ProjectBInfo ProjectBInfo { get; private set; }

        public void Create1() { }
        public void Create2() { }
    }
}

The info and creator classes share common interfaces. The creator needs info class for its operation.

Thank you!

Upvotes: 2

Views: 54

Answers (1)

TheAlgorist
TheAlgorist

Reputation: 133

This isn't TDD. With TDD, the purpose is to write the test first. If you write your test first, then a class hierarchy will come out of that test and it will be testable. In order to better understand TDD, please take a look at:

The Rules of TDD by Uncle Bob

If your question is just: Is this testable? Yes, it is testable.

Upvotes: 2

Related Questions