Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Strategy does not really work for you in this case.</p> <p>We must question why you must call ISomeInterface when its implementing classes do not support all methods. It is probably best to have several inheriting interfaces.</p> <ul> <li>ISomeInterface <ul> <li>IClassAInterface</li> <li>IClassBInterface</li> </ul></li> </ul> <p>Then, pick which Interface is most appropriate for usage. </p> <pre><code>interface ISomeInterface { string Id{get; set;} void Display(); } interface IClassAInterface { Dictionary&lt;string, string&gt; DataValues{get;}; } interface IClassBInterface { TypedDataSet MetaData{get; } IList&lt;Record&gt; RecordCollection{get; } } </code></pre> <p>The example usage you given isn't really helpful - you already know which class you are instantiating (new A() and new B()) so the interfaces aren't going to give you any added abstraction. So let us think of an example where this technique is more useful:</p> <pre><code>public class SomeCollection { public ICollection&lt;T&gt; retrieveItems&lt;T&gt;() where T : ISomeInterface { //... retrieve relevant instances. } } </code></pre> <p>Then </p> <pre><code>var col = new SomeCollection(); // Populate... var someInterfaces = col.retrieveItems&lt;ISomeInterface&gt;(); foreach(ISomeInterface instance in someInterfaces){ instance.Display(); } var classAInterfaces = col.retrieveItems&lt;IClassAInterface&gt;(); // etc. </code></pre> <hr> <p>So I guess in the end, if you're trying to get a bunch of "RecordCollection" from a collection of As and Bs, you really need to rethink your design.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      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