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

  • Home
  • SEARCH
  • 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 6545493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:35:32+00:00 2026-05-25T11:35:32+00:00

So my main class was getting quite large so I decided to encapsulate the

  • 0

So my main class was getting quite large so I decided to encapsulate the drawing of displays to its own class.

Then, on the OnPaint event handler I call displayDrawer.Draw();

The only problem is that in order to draw something the method needs quite a few arguments.

For example, there are four boolean arguments specifying flags that affect drawing. Example: whether or not to draw at all (don’t draw if the file isn’t loaded), tints, which layers to draw, et cetera. Then of course there is the offsets that need to be passed. Depending on the offset of the horizontal and vertical scrollbars or the width and height of the display, the drawer needs to react accordingly.

The reason these all need to be passed is because the class does not have access to the form’s controls. I rather not make the controls public or provide accessors and I don’t want to pass the form either.

The obvious answer is to create either a class or struct filled with the values like this:

class Offsets
{
    public int horizontal, vertical, displayWidth, displayHeight;

    public Offsets(int horizontal, int vertical, int displayWidth, int displayHeight)
    {
        this.horizontal = horizontal;
        this.vertical = vertical;
        this.displayWidth = displayWidth;
        this.displayHeight = displayHeight;
    }
}

class DrawingFlags
{
    public bool drawCurrentLayer, drawOtherLayers, drawDisplay;

    public DrawingFlags(bool drawCurrentLayer, bool drawOtherLayers, bool drawDisplay)
    {
        this.drawCurrentLayer = drawCurrentLayer;
        this.drawOtherLayers = drawOtherLayers;
        this.drawDisplay = drawDisplay;
    }
}

But is it all really worth it? These containers will only ever be used once in the program during that method call and then after that it’s just more lines of code to have to sift through. Should I just bite the bullet and accept that this one method call has a lot of parameters?

  • 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-25T11:35:33+00:00Added an answer on May 25, 2026 at 11:35 am

    Note that if you’re just creating a class with public properties, but you are populating that class with a constructor that takes a dozen parameters, then you are just pushing the same method parameter complexity from one place to another, and you are adding more complexity by incorporating the properties. Only do this if you get a net gain.

    For example, your class

    class Offsets 
    {
        public int horizontal, vertical, displayWidth, displayHeight;
    
        public Offsets(int horizontal, int vertical, int displayWidth, int displayHeight)
        {
            this.horizontal = horizontal;
            this.vertical = vertical;
            this.displayWidth = displayWidth;
            this.displayHeight = displayHeight;
        } 
    }
    

    can be modified to look like this:

    class Offsets
    {
        public int horizontal { get; set; }
        public int vertical { get; set; }
        public int displayWidth { get; set; }
        public int displayHeight { get; set; }
    }
    

    and can be populated like this

    var offsets = new Offsets { horizontal = 10, vertical = 20 ... }
    

    This is more readable, because you are giving a name to each parameter. It also intellisenses.

    Note that if you’re using C# 4.0, you don’t have to do any of this, as you have the benefit of named and optional parameters:

    var result = MyMethod(horizontal: 10, vertical: 20);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I subclassed UIScrollView Then created an object of it in the main class. Added
I have a question about the 'Event Dispatch Thread'. I have a Main class
This is getting made in a static void method in the main class. (class
I have a main class in a program that launches another class that handles
I have a small Java test app in Netbeans where the main() class reads
I am trying to run a function of the main class, but even with
I'm creating a website with structure like this: class main { } class mysql
For my Java apps with very long classpaths, I cannot see the main class
In the interface required to implement a WCF service, I declare the main class
In the below program: class Main { static string staticVariable = Static Variable; string

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.