Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>We are injecting (Spring.Net) such functionality into dictionaries by type.</p> <pre><code>IDictionary&lt;Type, IBlahImplementor&gt; blahImplementors; blahImplementors[thingy.GetType()].Do(thingy); </code></pre> <p>This dictionary could be managed by a kind of repository which provides the functionality.</p> <p>As an implementation detail, the implementor usually knows the type it depends on an can provide it itself:</p> <pre><code>interface IBlahImplementor { Type ForType { get; } void Do(object thingy); } </code></pre> <p>Then it is added to the dictionary like this:</p> <pre><code>IEnumerably&lt;IBlahImplementor&gt; blahImplementors; foreach (var implementor in blahImplementors) { blahImplementors.Add(implementor.ForType, implementor); } </code></pre> <hr> <p>Remark: IMHO, it is very important to understand that some things do NOT belong into a class, even if providing subtype-specific implementations would make life much easier.</p> <hr> <p><strong>Edit</strong>: Finally understood your concrete example.</p> <p>It is actually about instancing the right UI control to show the pricing models parameters. It should be possible with the pattern I described above. If you don't have a single UI control for a pricing model, you either create it or you write a UI configurer or something like this which sets up the required controls.</p> <pre><code>interface IPricingModelUiConfigurer { Type PricingModelType { get; } void SetupUi(Control parent, IPricingModel model); } </code></pre>
 

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