Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If the defaults depend on the receiver of the method call, declare them as interface methods.</p> <p>If the defaults are just defaults irrespective of the receiver, create the various reduced-argument-list overloads as extension methods and save implementors the headache of having to supply all the overloads themselves.</p> <p>If you're dealing with some sort of nitty-gritty 80/20 rule exceptions, where implementation-independent defaults are <em>almost but not quite</em> always sufficient, you have a few options, none of which are that good:</p> <ul> <li>Deal with it as if they're always different, declare them as interface methods, and reimplement them everywhere. Not very DRY.</li> <li>Deal with it as if they're always different, declare them as interface methods, and inherit a base class that provides the 80% default implementation. Kind of clumsy, and not good if your sole base-class slot is already occupied.</li> <li>Create another interface containing those specific methods. Declare extension methods with matching signature against the original interface. In the extension methods, <code>as</code>-cast the <code>this</code> argument to the new interface type, and if it matches, call it there, otherwise fill in stock defaults. Very funky, reliant on dynamic casting so not that great in an inner loop, but it decouples the defaults from both implementor and caller without sacrificing flexibility for implementors that can't take the "default defaults".</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload