Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you described is pretty much exactly the use case for the <a href="http://en.wikipedia.org/wiki/Visitor_pattern" rel="nofollow">Visitor Pattern</a>.</p> <p><strong>EDIT</strong>: For your concrete example, you could apply the visitor pattern like this:</p> <pre><code>// interface used to add external functionality to pricing models public interface PricingModelVisitor { void visitPricingModel1(PricingModel1 m); void visitPricingModel2(PricingModel2 m); ... } // your existing base-class, with added abstract accept() method to accept a visitor public abstract class PricingModelBase { public abstract void accept(PricingModelVisitor v); ... } // concrete implementations of the PricingModelBase implement accept() by calling the // appropriate method on the visitor, passing themselves as the argument public class PricingModel1 : PricingModelBase { public void accept(PricingModelVisitor v) { v.visitPricingModel1(this); } ... } public class PricingModel2 : PricingModel { public void accept(PricingModelVisitor v) { v.visitPricingModel2(this); } ... } // concrete implementation of the visitor interface, in this case with the new // functionality of adding the appropriate controls to a parent control public class ParameterGuiVisitor : PricingModelVisitor { private Control _parent; public ParameterGuiVisitor(Control parent) { _parent = parent; } visitPricingModel1(PricingModel1 m) { // add controls to _parent for PricingModel1 } visitPricingModel2(PricingModel2 m) { // add controls to _parent for PricingModel1 } } </code></pre> <p>now, instead of using a big <code>if</code>-<code>else</code> block when you need to display the edit-controls for the parameters of a specific subtype of <code>PricingModelVisitor</code>, you can simply call</p> <pre><code>somePricingModel.accept(new ParameterGuiVisitor(parentControl)) </code></pre> <p>and it will populate the appropriate GUI for you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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