Mediator Pattern or Windows Event-based Pattern for the UI?

Hello. I am partly done on the business object coding and am now engaging on the windows forms coding. We are actually designing reusable user controls since a number of these user control components can be used on a different project.
In this note I am now delving in complicated way of updating/notifying/synchronizing my user controls on a form. Do I use the event-based type of pattern to notify my main form of a change that happened to a user control which in turn will update another user control or do I use the Mediator Pattern
I originally leaned on the Mediator Pattern because it would put all the control synhronization code in a single Mediator class but the problem with this is that I can only define an abstract method for the user controls Update_Colleague(sender as IColleague, data as object). The "data" I am passing-in is not strongly-typed, whereas when using events, each user control can dictate the argument that it passes along when the user control raises the event.
Using Mediator Pattern these are the interfaces in my mind:
Interface IMediator
NotifyMediator(source IColleague, data as obejct)
End Interface
Interface IColluage
Property Mediator() as IMediator
UpdateColleague(source as IColleage, data as object)
End Interface
======================================
Using Events a User Control can raise events like:
Class UserControl1
Event DataWasUpdated( sender as object, args as UserControlEventArgs)
Sub SomeControl_Clicked(xxx,xxx) Handles SomeControl.Click
' Do some work on the UserControl
RaiseEvent DataWasUpdated( me, new UserControlEventArgs(somedata)
End Sub
End Class
The Main UI Form just handles the events raised by the user control and so on. All these interactions can be organized in a block of code using the #Region.
#Region "UI Interactions"
Sub UserControl1_DataWasUpdated(sender as object, args as UserControlEventArgs)
'Do some work on the Main Form
' Update another UserControl's State
End Sub
#End Region
I looked into the composite ui application block (CAB) but this is way too complicated to implement for the size of the project.
Any thoughts


Answer this question

Mediator Pattern or Windows Event-based Pattern for the UI?

  • BrandtSmith

    I would use events to raise notifications when an object changes, and when I read your code it looks to me that you can better implement the observer pattern than the mediator, becouse you want to send notification to other controls that the state is changed.

  • Mediator Pattern or Windows Event-based Pattern for the UI?