interfaces,

V

vsgdp

Is it considered to be bad form to have an abstract method where some of the
parameters are ignored by derived classes?

I'm writing a class that contains an abstract method. The output of the
method can depend on several parameters (but could also only depend on just
one of them). So my idea was to always pass all the parameters, then
derived classes can pick and choose which parameterrs to use in the
implementation of the method.
 
P

Phlip

vsgdp said:
Is it considered to be bad form to have an abstract method where some of
the parameters are ignored by derived classes?

To rate a design, imagine how easily you could extend it in the future.
I'm writing a class that contains an abstract method. The output of the
method can depend on several parameters (but could also only depend on
just one of them). So my idea was to always pass all the parameters, then
derived classes can pick and choose which parameterrs to use in the
implementation of the method.

That might cause a bad surprise when you add a new class or method. You
might have trouble figuring out why it's not working - because the derived
class neglects the parameter you upgraded.

You may like a Visitor or Double-Dispatch pattern there. The argument you
pass in is itself a type with virtual functions, and they in turn find the
target behaviors.
 
V

Victor Bazarov

vsgdp said:
Is it considered to be bad form to have an abstract method where some
of the parameters are ignored by derived classes?

It seems like some paradigm is pulled by the ears to fit an artificial
requirement of some sort.
I'm writing a class that contains an abstract method. The output of
the method can depend on several parameters (but could also only
depend on just one of them). So my idea was to always pass all the
parameters, then derived classes can pick and choose which
parameterrs to use in the implementation of the method.

Can you give a less abstract (lacking a better word) description of
what you're trying to model?

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top