Well, it's not a false statement. You can achieve dynamic/runtime polymorphism (late binding) using interfaces but you can also use base classes or abstract classes where the underlying concrete type is determined at runtime. An example of late binding. ..
Supposed you have the following interface
interface IOrder
{
void ProcessOrder(int orderId);
void ProcessOrder(int orderId, int userId);
}
Then you have an order object that implements this interface...
public StoreAOrder : IOrder {...}
And then you use dependency injection to process an order...
public class OrderProcessor
{
private IOrder order;
public OrderProcessor(IOrder _order)
{
order = _order;
}
public void Process()
{
order.ProcessOrder(id, User.Current.Id);
}
}
Notice that at compile timw the OrderProcessor
doesn't really know what is the concrete class that implements IOrder
. Furthermore, it doesn't know anything about the overloads that the underlying object exposes. This is what is called runtime polymorphism.