0

I have some classes that have outline like this

class A{
    //class A elements
    A(typeA1 A1, typeA2 A2, ....){//initialize elements}
}

class B extends A{
    //class B elements
    B(typeA1 A1, typeA2 A2,...... typeB1 B1, typeB2 B2, ....)
    {
        super(typeA1 A1, typeA2 A2,......);
        //initialize B elements
    }
}

What I am doing to construct B class is pass arguments of both A and B to B's constructor and then call A's constructor through it.

But this gets dirty as number of elements go on increasing. What is a better(maybe with less no of arguments?) way to achieve this?

Registered User
  • 2,239
  • 3
  • 32
  • 58
  • 1
    You should avoid an extensive list of parameters. Think about you architecture. If you need all this data, construct appropriate classes to hold the data and use it as parameter. – J Fabian Meier Jul 19 '16 at 14:50
  • If you face the issue of having too many arguments (or fields), you might want to think about refactoring steps. Maybe the code should be split into several classes? – C-Otto Jul 19 '16 at 14:50

0 Answers0