views:

257

answers:

1

As a plugin framework developer, I want to specify an interface, myNameSpace.IPlugin, that the plugins must implement. The return value of one of the interface members, IPlugin.GetWidget(), must be of a type derived from System.Windows.Forms.Control and it also must implement myNameSpace.IFoo interface. I also want to allow the plugin developers to return third party controls (which are already System.Windows.Forms.Control descendents) from IPlugin.GetWidget(). What is the best way to unambiguously specify this requirement , other than documenting it, ofcourse :) , and enforce it ? How would a plugin developer go about desigining a plugin (using a 3rd party control) to meet these requirements ?

+1  A: 

Your design smells a little fishy. Why must widgets both inherit from a concrete class and implement another unrelated interface? Sounds like you're a little inheritance-happy. Instead of that, try this:

interface IPlugin
{
    IWidget Widget { get; }
}

interface IWidget
{
    System.Windows.Forms.Control Control { get; }
    IFoo Foo { get; }
}

Whether IFoo is implemented by the control itself or by another class should really be up to the implementer. Your code shouldn't care.

munificent