P
pauldepstein
I am working with a class which has a constructor which takes several
parameters:
class MyClass {public: MyClass(SomeType A, SomeOtherType B,
YetAnotherType C) {} // ....}
I want to amend MyClass slightly so that it takes more parameters:
class MyClass {public: MyClass(SomeType A, SomeOtherType B,
YetAnotherType C, AddOneMoreType D) {} // ....}
I am told not to do that because MyClass should not be changed and
because adding more parameters is seen as unwieldy. I am told to
derive a class from MyClass and to add the extra parameters such as D
of type AddOneMoreType etc. to the derived class. This must be quite
a common thing to do but I'm not sure how to design this.
Something like class MyNewClass: public MyClass{ public:
MyNewClass(AddOneMoreType D){} } but this doesn't work because this
doesn't reflect the fact that members of MyNewClass also take
parameters A, B and C from the base class.
Another idea is class MyNewClass: public MyClass{ public:
MyNewClass(SomeType A, SomeOtherType B, YetAnotherType C,
AddOneMoreType D) {} } but that leads to the objection that using
too many parameters in the constructor is seen as unwieldy.
Thank you for any suggestions.
Paul Epstein
parameters:
class MyClass {public: MyClass(SomeType A, SomeOtherType B,
YetAnotherType C) {} // ....}
I want to amend MyClass slightly so that it takes more parameters:
class MyClass {public: MyClass(SomeType A, SomeOtherType B,
YetAnotherType C, AddOneMoreType D) {} // ....}
I am told not to do that because MyClass should not be changed and
because adding more parameters is seen as unwieldy. I am told to
derive a class from MyClass and to add the extra parameters such as D
of type AddOneMoreType etc. to the derived class. This must be quite
a common thing to do but I'm not sure how to design this.
Something like class MyNewClass: public MyClass{ public:
MyNewClass(AddOneMoreType D){} } but this doesn't work because this
doesn't reflect the fact that members of MyNewClass also take
parameters A, B and C from the base class.
Another idea is class MyNewClass: public MyClass{ public:
MyNewClass(SomeType A, SomeOtherType B, YetAnotherType C,
AddOneMoreType D) {} } but that leads to the objection that using
too many parameters in the constructor is seen as unwieldy.
Thank you for any suggestions.
Paul Epstein