Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:10:10+00:00 2026-06-16T00:10:10+00:00

I have a design question. I’m working with a Coded UI test framework that

  • 0

I have a design question. I’m working with a Coded UI test framework that someone wrote and I am maintaining. I am convinced the way this is designed incorrectly but I thought I would get some other opinions. It’s basically a large static class whose sole purpose is to create and return other objects.

Good/Bad…why? I am lobbying to take on a pretty significant refactor and want to please my case convincingly to my manager.

public static class ParentClass
{
    private static ChildClass1 childClass1;
    private static ChildClass2 childClass2;
    // 10+ more of the same

    // Properties
    public ChildClass1 ChildClass1
    {
        get 
        {
            if (childClass1 == null)
            {
                childClass1 = new ChildClass1();
            }
            return childClass1;
        }
     }

    public ChildClass2 ChildClass2
    {
        get 
        {
            if (childClass2 == null)
            {
                childClass2 = new ChildClass2();
            }
            return childClass2;
        }
    }
    // 10+ more of the same
}



[TestClass]
public class TestClass1
{
    [TestMethod]
    public void TestMethod1()
    {
        var x = ParentClass.ChildClass1.SomeMethod();
        Assert.IsNotNull(x);
    }

    [TestMethod]
    public void TestMethod2()
    {
        var x = ParentClass.ChildClass2.SomeMethod();
        Assert.IsNotNull(x);
    }

    // 10+ more of the same
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:10:11+00:00Added an answer on June 16, 2026 at 12:10 am

    This is something like a singleton pattern but it does not become clear from the provided code why it is designed this way.

    var x = ParentClass.ChildClass1.SomeMethod();
    

    could easily be replaced with

    var x = new ChildClass1().SomeMethod();
    

    and then you can get rid of ParentClass.ChildClass1 and ParentClass.childClass1 unless ParentClass.ChildClass1 is used several times and carries state from method call to method call.

    But while this does not really look elegant and might be overly verbose, I would not consider this a major issue.

    Personally I would have implemented it this way but it is hard to tell if this would work for all the omitted code.

    [TestClass]
    public class TestClass1
    {
        private static void ExecuteTestCore<T>() where T : new(), IHaveAMethod
        {
            var x = new T().SomeMethod();
    
            Assert.IsNotNull(x);
        }
    
        [TestMethod]
        public void TestMethod1()
        {
            TestClass1.ExecuteTestCore<ChildClass1>();
        }
    
        [TestMethod]
        public void TestMethod2()
        {
            TestClass1.ExecuteTestCore<ChildClass2>();
        }
    
        // 10+ more of the same.
    }
    
    internal interface IHaveAMethod
    {
        void SomeMethod();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is a CSS / design question. I have three textboxes that i want
This is more of a design question that others may have had similar experience
This is a tough design question for a application I'm working on. I have
This is more of a design question. I have a template class, and I
This is more of a general design question I guess... I have an Ajax
This is probably more a design or style question: I have just been considering
I have a question regarding my database design and its implementation that i am
This is more of a design question. I have a single ViewController which manages
This is a technical design question more then a syntax question. I have a
This is more of a design question. Suppose you have a method like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.