To: Jay Tuley – Subject: about DuckTyping

Hello Jay! I have been using ImpromptuInterface for some months. I’m making a PCL in .NET and it happens that, when trying to abstract any behavior, I face the very common annoyance that .NET Framework is very possessive with its types and interfaces. Sometimes a type doesn’t implement any interface, or when it does, the interface is internal.

So this is the problem: I have an interface with the same exact methods, with the same return types and method signatures. This is really easy. I just call the extension method

dotNetUglyAndPossessiveInstance.ActAs<MyBeautifulInterface>();

and I get exactly what I want. Transparent and handy.

But, what to do when some methods are slightly different?

  • Different names
  • Different call site: one is a property getter and the other is a method
  • Some methods that are different

Normally, they take a pure OOP approach and recommend the creation of Adapters. But when you have a complex hierarchy of types, this can be really tedious and complex as well, even more when you have HUGE classes like UIElement, Control, FrameworkElement…

What do you think it’s the best approach?

Thanks!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s