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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:21:54+00:00 2026-06-04T14:21:54+00:00

So with inheritance I always find my self dealing with extremely long constructors in

  • 0

So with inheritance I always find my self dealing with extremely long constructors in the most specific classes. I am looking for a paradigm or method by which I can avoid this problem. I’ve thought of using factories, but if I did, I would still have to use the constructor in the factory. Regardless of that thought, is there anything I can do to keep constructor parameter length down?

For example:

abstract class DrawableComponent : Component, ITransformable, IScalable, IDrawable, IRotatable

Is a child class with a constructor like

DrawableComponent(string Name, int SizeX, int SizeY, int X, int Y, float Rotation) : base(Name) { ... }

Now let’s say I’d like to make a child of that. Things just get more complex and ugly.

class TextBoxComponent : DrawableComponent, IRenderable

The constructor now gets extremely long:

public TextBoxComponent(
    IDrawableUnit Background,
    IDrawableUnit Text,
    string Name,
    int X,
    int Y,
    int SX,
    int SY)
: base(Name, SX,SY,X,Y,0.0f)
{
    this.Background = Background;
    this.Foreground = Foreground;
}

In summary of this, I’m sick of having things like this:

class Blah {Blah(blah)}
class childBlah : Blah {childBlah(blah,blahs,blaha) : base (blah)}
class grandChildBlah : childBlah {grandChildBlah(blah, blahs, blaha, blaht, blauh) : base(blah,blahs,blaha) }
  • 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-04T14:21:55+00:00Added an answer on June 4, 2026 at 2:21 pm

    If you have really long constructor parameter lists, then you must have many fields in a single class? This indicates that you should think about splitting those classes into more than one class, or extracting groups of related fields into their own types.

    For example, x and y coordinate fields or width and height values:

    private double mX;
    private double mY;
    private double mWidth;
    private double mHeight;
    

    should really be a single point or vector or rectangle object:

    private vector mPosition;
    private vector mSize;
    
    // or
    
    private rectangle mRegion;
    

    Another suggestion might be to reduce your inheritance, and instead use composition. Instead of an is-a relationship, use a has-a relationship:

    Your ‘blah’ example then becomes something like:

    class Blah
    {
       Blah(int blah) { ... }
    }
    
    class ChildBlah
    {
       Blah mBlah;
       ...
       ChildBlah(Blah blah, int blahs, int blaha)
       { mBlah = blah; ... }
    }
    
    class GrandChildBlah
    {
       ChildBlah mChildBlah;
       ...
       GrandChildBlah(ChildBlah blah, int blaht, int blahu)
       { mChildBlah = blah; ... }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which inheritance makes more sense : class SequentialIterator{ SequentialIterator next(); }; class RandomAccessIterator :
If I use inheritance, and later realize that a single subclass needs a method
I want a subclass to use its parent's constructors. But it seems I always
I've always wondered since i learned about prototype inheritance why you push an instance
When doing inheritance in JavaScript, the pattern that I always see defines instance methods
When I design classes and have to choose between inheritance and composition, I usually
in our system we store orders. We always have customer specific code in our
I'm making a Gui Api for games. The user can always use inheritance on
This inheritance is found in ADO.Net. Can we say that here both the design
Is the multiple inheritance in Java and Perl the same?

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.