OO - Reduce boilerplate/forwarding code
<p>Imagine the following: I have a bunch of DTO's that inherit from <strong>Foo class</strong></p>

<pre><code>    class Foo { }

    class FooA : Foo { }

    class FooB : Foo { }

    class FooX : Foo { }
</code></pre>

<p>Than I have one class that have encapsulated all the related logic and orchestration related with <code>Foo</code> data types. I provide a method  <code>DoSomethingWithData(Foo data)</code> that do all the logic related to data provided by argument</p>

<p>The method implementation is something like this:</p>

<pre><code>void DoSomething(Foo data)
{
     if (data is FooA)
           DoSomethingWithFooA((FooA) data);
     if (data is FooB)
           DoSomethingWithFooB((FooA)data);
     if (data is FooX)
           DoSomethingWithFooC((FooA)data);
}
</code></pre>

<p>This is a very simplified example. The advantage of this approach is:</p>

<ul>
<li>The "Client" invoke always the <code>DoSomething</code> method independently of
the <code>Foo</code> data type</li>
<li>If I add a new type I only have to change the method <code>DoSomething</code></li>
</ul>

<p>What i dont like is the downcasting</p>

<p>The alternative is instead of exposing only <code>DoSomething</code> method I expose a method by each <code>Foo</code> data type. The advantage is that we dont have downcast but increases the boilerplate/forwarding code.</p>

<p>What do you prefer? Or do you have other approaches? </p>