Accessing derived class properties when implementing an interface method with abstract base class as parameter
<p>I tried hard to find an answer to this question, so if it is has been asked already, perhaps I'm wording it wrong. I have an abstract base class and a derived class.</p>

<pre><code>abstract class Foo
{
   protected int property1
   protected int property2
// etc..
}
</code></pre>

<p>My dervied class contains some extra properties that are not found in the base class:</p>

<pre><code>class Fum : Foo
{
   public int UniqueProperty { get; set; }
}
</code></pre>

<p>Now I have an interface with a method that takes the abstract base class:</p>

<pre><code>interface IDoSomethingWithFoos
{
   void DoSomethingWithFoo(Foo fooey);
}
</code></pre>

<p>A class that implements the interface</p>

<pre><code>class FumLover : IDoSomethingWithFoos
{
   void DoSomethingWithFoo(Foo fooey)
   {
      // now in here i know i am going to be passed objects of Fum
      // and i want to access its unique properties

      fooey.UniqueProperty = 1;   // this doesn't work

      ((Fum)fooey).UniqueProperty = 1;   // this seems to work

      // as does..

      Fum refToFum = fooey as Fum;
      refToFum.UniqueProperty = 1;

   }
}
</code></pre>

<p>So my question is: am I going about this in the right way? Although this compiles, I don't have enough code in place to make sure yet it is actually going to work properly. And my other question is: is this bad design? Is there a better way?</p>

<p>*</p>

<p>To elaborate a little more, because the natural response is, if you are going to be passing Fum, then have the interface method take a Fum instead of a Foo.</p>

<p>But let's say in my FumLover class, the method DoSomethingWithFoo deals 95% with properties that ARE in the abstract bass class. And let's say I have another derived class called Fie, which has a couple of unique properties. Now let's say I have a FieLover class, and I want to implement DoSomethingWithFoo because 95% of what I'm going to do here could apply to all Foo, but again, there is a little bit that is unique to Fie.</p>

<p>What is the alternative? To have an interface for each one: IDoSomethingWithFums, IDoSomethingWithFies, etc.? It seems like I lose all the abstraction for just that 5% of difference.</p>
