I have two interfaces:
public interface IController
{
void doSomething(IEntity thing);
}
public interface IEntity { ... }
One example implementation would be:
public class ControllerImplA : IController
{
public void doSomething(IEntity entity)
{
EntityImplA entityForA = (EntityImplA)entity;
...
}
}
public class EntityImplA : IEntity { ... }
The entity parameter of ControllerImplA.doSomething() will always be EntityImplA. Likewise, the entity parameter of ControllerImplB.doSomething() will always be EntityImplB, and so on so forth for other implementations.
Is there a way to avoid using the downcasting in my current code? In other words, I want to do something like this:
public class ControllerImplA : IController
{
public void doSomething(EntityImplA entity) { ... }
}
without modifying the interfaces? What about if abstract parent classes are used instead of interfaces?