views:

68

answers:

2

Hi !

I have a design questions about this scenario: Suppose you have a form with many sites to be filled, let's call each site a plugin. Among other classes I've created a PluginManager class that takes evidence of all plugins and provides some functionality and properties:

class PluginManager
{
  ...
  BasePlugin CurrentPlugin {get;set;}
  IEnumerable<BasePlugin> OpenedPlugins {}
  bool SetPlugin() {..}
  ...
}

class BasePlugin {}
class MyPlugin : BasePlugin {}

Among other thins, it handles displaying the chosen plugin / site.

Until now I never needed to communicate between 2 or more plugins. Now I do and I wanted to ask you, how would you do that.

My opinion was to add en Event to the BasePlugin class and handle it in PluginsManager class, in some way, that the Plugin raising the Event would provide in the EventArgs the types of all other Plugins that should be affected and a list of delegates pointing at the methods that should be executed.

Do you have any idea? Thank you !

+2  A: 

Have a look at the "Chain Of Responsibility" Pattern. The plug-in calls the manager to get some information from anywhere. The manager asks each plug-in to put the information into a provided interface. (What is a kind of a Visitor Pattern).

Greets Flo

Florian Reischl
I suggested the Mediator pattern, which is a 'push' method (plug-in would broadcast information), while you have suggested Chain of Responsability as a 'pull' method, which I woudn't have thought of! +1 for you.
Dr Herbie
@Dr Herbie: and +1 for you for another nice idea :-). As you already mentioned, it always depends.
Florian Reischl
+1  A: 

Sounds like a possible Mediator Pattern to me (see also here for a description with C# code).

A mediator class handles communications between other classes. Your PlugInManager class would have a private Mediator instance and all the plug-ins would register with the mediator to receive communications.

There are probably 101 ways to do this, so expect a variety of answers.

Dr Herbie