interfaces,

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vsgdp

    #1

    interfaces,

    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.




  • Phlip

    #2
    Re: interfaces,

    vsgdp wrote:
    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.

    --
    Phlip
    http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!


    Comment

    • Victor Bazarov

      #3
      Re: interfaces,

      vsgdp wrote:
      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
      --
      Please remove capital 'A's when replying by e-mail
      I do not respond to top-posted replies, please don't ask


      Comment

      Working...