Link to home
Start Free TrialLog in
Avatar of scarface7
scarface7

asked on

Delegates and Events as component technology for GoF Observer pattern ?


I am a college student trying to build a small Windows Application in Visual Studio 2005.

Business Context:

Simulation of Computer science department that contains faculty, students, courses, programs, registration process etc.

My Question:

One aspect of the project requires me to simulate students enrolling/dropping classes, and the automatic notification to a faculty member when an enrollment is reached. Is delegates and events the best way to implement this in C# ? Does this involve a lot of code? Any good implementation strategies on this with respect to C# ?

Is there any good component technology that can be readily used to capture the Gang of Four Observer design pattern that can be applied to the above problem ?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of PoeticAudio
PoeticAudio

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PoeticAudio
PoeticAudio

oops. forgot... We need to set things in motion... Here is where we call the CountToTen method, notice that we get a message box because once it hits ten, the OnCountedToTen event is raised.

private void button_Click(object sender, System.EventArgs e)
{
    numberCounter.CountToTen();
}
So if you wanted to use events then you could raise an event when a student is enrolled. Then another class can handle that event and do what it needs to do. Since this is homework I don't want to give away too much, but you could definitely use events in your situation (which really is pretty much the observer pattern).
CORRECTION:

The line that reads:
the observer notifies all of the "subjects" when something interesting happens

should read:
the "subject" notifies all of the "observers" when something interesting happens.

Sorry about the confusion.
Avatar of scarface7

ASKER

Nice explanation !