title: Using a Func<> over an interface?
body: <p>I have an already existing generic class</p>
  
  <pre><code>public class Foo&lt;T&gt;
  {
      private T _item;
      public Foo(T item){ _item = item;}
  }
  </code></pre>
  
  <p>I have to create a method which will return a certain property of T.<br>
  I see two solutions here. </p>
  
  <ol>
  <li><p>Creating an interface :</p>
  
  <pre><code>public const string TestVar = "bar";
  public interface INamable { string Name { get; } }
  public class Bar : INamable
  {
      public string Name { get { return TestVar; } }
  }
  
  public class Foo&lt;T&gt; where T : INamable
  {
      private T _item;
      public Foo(T item) { _item = item; }
      public string GetName() { return this._item.Name; }
  }
  
  [TestMethod()]
  public void TestInterface()
  {
      var bar = new Bar();
      var foo = new Foo&lt;Bar&gt;(bar);
      Assert.AreEqual(TestVar, foo.GetName());
  }
  </code></pre></li>
  <li><p>Passing a Func :</p>
  
  <pre><code>public const string TestVar = "bar";
  public class Bar
  {
      public string Name { get { return TestVar; } }
  }
  
  public class Foo&lt;T&gt;
  {
      private T _item;
      private Func&lt;T, string&gt; _funcName;
      public Foo(T item, Func&lt;T, string&gt; funcName) { _item = item; _funcName = funcName; }
      public string GetName() { return _funcName.Invoke(_item); }
  }
  
  [TestMethod()]
  public void TestFunc()
  {
      var bar = new Bar();
      var foo = new Foo&lt;Bar&gt;(bar, b =&gt; b.Name);
      Assert.AreEqual(TestVar, foo.GetName());
  }
  </code></pre></li>
  </ol>
  
  <p>I go with the second solution, since I don't have to create an interface, and I'm lazy. Just have to add one parameter to the already call of the foo constructor.</p>
  
  <p>Moreover, the Foo class can still be used with all sort of class, and I prefer it this way.</p>
  
  <p>BUT, I'm not sure if it is the good way to use a Func? Is it still nice and SOLID? This is my first try to use a Func, that's why I'm asking myself! </p>
  
  <p>A couple of months ago I used the first solution, with classic interface...</p>