Reputation: 12283
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 !
Upvotes: 0
Views: 619
Reputation: 3940
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.
Upvotes: 1
Reputation: 3866
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
Upvotes: 2