First of all this is all just concept, I have no actual programming done yet. This is the situation:
I have a Class A which uses the Filesystemwatcher to watch for changes in a folder. (using events)
Then I have a ‘Collection Class’ B which has a List of A’s.
Now what I want to happen is as follows,
A Change happens with the folder, A detects this and sends a message to B, B transfers this message to Class C. Class C then begins a method which updates the GUI. (What changes were made etc..)
Now I have searched and thought pretty long on this subject, but can’t find the solution. But, I have found 2 design patterns:
Mediator and Observer.
As a software engineer I have to some degree once made the Observer pattern so I know some of the basics there.
Now to my questions:
-
What pattern is best to use in this situation?
-
How do I make it so that B transmits the message to C?
-
Do I need custom Events / delegates to make A transmit data to B or can I use the Built-in events?
P.S.: I’m using C# as my programming language.
edit: Thanks to everyone for helping me, votes are on the way.
For what I make out of this, there are a bunch of ‘A’ objects that pass on events asynchronously to a single B, that in turn passes that info on to a single C.
So, let B contain and observe the A’s and let C observe B.
If you got a lot of A’s, you might want to have B do some gathering/caching of A’s events before notifying C. Especially if C is serving a user interface.
Side note: don’t over-patternize your software. Try to be open-minded and always find the simplest and easiest solution. Only use a pattern where its appropriate, and not just because it’s possible. I have seen many people throwing in proxies, command-patterns, observers, MVC’s, mediators etc, where they were unneccesary.
Good luck.