Note that there are some explanatory texts on larger screens.

plurals
  1. POIs strategy pattern helpful for this scenario?
    primarykey
    data
    text
    <p>I have two classes A &amp; B and both class implements the interface ISomeInterface. But some properties are not required for both class A &amp; B. But in the client app I am calling the same ISomeInterface to invoke both the classes. The problem which I have is I don't want <code>Dictionary&lt;string, string&gt;</code> &amp; TypedDataSet, <code>IList&lt;Record&gt;</code> properties in the same interface. But the clients needs to use this IsomeInterface.</p> <p>Actually DataValues() property is only applicable to class A. Similarly MetaData() and RecordCollection() properties are applicable to class B. Also, if I introduce a new class C in future and that needs a separate property like this then my code will look ugly which I don't want. So, Is there any way I can still use the same IsomeInterface in my client app and have the appropriate properties in the corresponding classes? I think I need to use Strategy Design pattern but got confused on how to implement the same. correct me if I am wrong?</p> <p>See below:</p> <pre><code>interface ISomeInterface { string Id{get; set;} void Display(); Dictionary&lt;string, string&gt; DataValues{get;}; TypedDataSet MetaData{get; } IList&lt;Record&gt; RecordCollection{get; } } public class A: ISomeInterface { public string Id { return "A1"; } void Display() { Console.Writeline("class A"); } public Dictionary&lt;string, string&gt; DataValues() { return new Dictionary&lt;string, string&gt;(); } public TypedDataSet MetaData() { //I dont want this method for class A throw new NotImplementedException(); } public IList&lt;Record&gt; RecordCollection() { //I dont want this method for class A throw new NotImplementedException(); } } public class B: ISomeInterface { public string Id { return "B1"; } void Display() { Console.Writeline("class B"); } public Dictionary&lt;string, string&gt; DataValues() { //I dont want this method for class B throw new NotImplementedException(); } public TypedDataSet MetaData() { return new TypedDataSet(); } public IList&lt;Record&gt; RecordCollection() { IList&lt;Record&gt; rc = null; //do something return rc; } } </code></pre> <p>Client App -</p> <pre><code>Main() { ISomeInterface a = new A(); a.Display(); Dictionary&lt;string, string&gt; data = a.DataValues(); ISomeInterface b = new B(); b.Display(); TypedDataSet data = b.MetaData(); IList&lt;Record&gt; rc = b.RecordCollection(); } </code></pre>
    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.
 

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