What is the best way to implement polymorphic behavior in classes that I can’t modify? I currently have some code like:
if(obj is ClassA) { // ... } else if(obj is ClassB) { // ... } else if ...
The obvious answer is to add a virtual method to the base class, but unfortunately the code is in a different assembly and I can’t modify it. Is there a better way to handle this than the ugly and slow code above?
Hmmm… seems more suited to Adapter.
Seems like a lot of code, but it will make the client code a lot closer to what you want. Plus it’ll give you a chance to think about what interface you’re actually using.