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 7183251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:56:29+00:00 2026-05-28T17:56:29+00:00

In my windows forms project I have a parent form that is creates other

  • 0

In my windows forms project I have a parent form that is creates other user controls and then places on a TabControl. My problem is that the code in the parent form is getting very large and difficult to manage.

In my parent form I have methods that look like this:

public SubControl1 CreateSubControl1(Guid ID, Info userInfo, bool populate)
public SubControl1 CreateSubControl1(Guid ID, Info userInfo, bool populate, StateType1 state)

public SubControl2 CreateSubControl2(Guid ID, Info userInfo, bool populate, String dataFile, String dataFile2, )
public SubControl2 CreateSubControl2(Guid ID, Info userInfo, bool populate, String dataFile, String dataFile2,  StateType2 state)

private SubControl3 CreateSubControl3(Guid ID, Info userInfo, bool populate, String dateFile)
private SubControl3 CreateSubControl3(Guid ID, Info userInfo, bool populate, String dateFile,  StateType3 state)

private SubControl4 CreateSubControl4(Guid ID, Info userInfo, bool populate, WorkingFolder wf)
private SubControl4 CreateSubControl4(Guid ID, Info userInfo, bool populate, WorkingFolder wf, StateType4 state)

At the moment depending on which SubControl (1-4) I want I create I call the corresponding CreateSubControlX method. This works OK for now, however I am sure there is a better way of doing this perhaps by harvesting off all the creational code to a sort of factory class.

However, because each of my derived types, have slightly different input parameters I am wondering how to do this? Should I create a ‘Simple’ factory that has a general Create method that takes in all the possible types of parameters and a type (to distinguish which SubControl 1 to 4 to create). I could then use null for any parameters I don’t want to set. This seems like a bad idea to me.

E.g. ControlFactory.Create(ID, userInfo, false, null, null, null, SubControlType1)

BaseControl is the base class for all types of controls e.g. SubControl1 to SubControl4.

Can anyone offer any help?

  • 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-05-28T17:56:31+00:00Added an answer on May 28, 2026 at 5:56 pm

    What ever you do, do not create one mega method with a bezillion parameters. It makes the code unreadable, and it makes life difficult for the people who will have to write code to call that method (including you).

    I mean really. Look at this method call and tell me what it does:

     ControlFactory.Create(ID, userInfo, false, null, null, null, SubControlType1)
    

    You can’t. With three null args and a true/false, it’s unreadable, unmaintainable code.

    Make multiple overloaded or similar named methods that are as specific as you can make them. For frequently used methods, I would consider eliminating one of the boolean args by creating two methods, one hard coded to the True case and one hard coded to the False case. These call a common internal function that takes a boolean arg for code sharing but not expected to be used by outside consumers. You always want the most frequently performed actions to require the shorted path to complete – in terms of code execution and in terms of keystrokes required to get there.

    The path to creating methods (APIs) that are easy to use is in reducing the number of parameters, using types that are descriptive (enum better than boolean), and method and parameter names that aid in discovery via code completion tooltips. Every time you go against this mantra you’re creating a lot of extra work and complexity for yourself and everyone else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows Forms project in Visual Studio that reads configuration files from
I have a treeview control in a Windows Forms project that has checkboxes turned
I have a VB.NET Windows Forms project that at one point paints text directly
I have a windows forms (.net 3.0) project that won't run on my customer's
I have been working on a project that has 2 interfaces - windows forms
I have a C# Windows Forms project with a Form containing 2 ListBoxes and
I have setup a windows forms project to use localization so that it will
I am working on a windows forms project that will allow a user to
I have a Windows Forms project. For some controls the property Image has value
VB.NET Windows Forms Project, VS2010. I have a tabcontrol with several tabpages and on

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.