views:

322

answers:

1

In terms of communicating different messages within an app would a good idea be to create a class for each message type? Some of my messages will need a reference a model object.

For example DoThisMessageType:

Messenger.Default.Send<DoThisMessageType>(_doThisMessageType);

Messenger.Default.Register<DoThisMessageType>(this, delegate(DoThisMessageType dt)
{
  // do something
}); 

How do you use messages in your applications? Do you keep them all together in one spot?

+3  A: 

Definitely have a different class for each message type. This helps keep registration of handlers simple.

To help group your message types together, I would suggest having a MessageBase type that they all derive from. This opens up multiple ways of discovering all the message types that your app handles - using Reflection for example, or Resharper's Go to Implementation feature.

Samuel Jack
Yes, recommended. You could also use a Structure to hold message type strings too. Dim X as new NotificationMessage(Of String)(MessageTypes.DoSomething1) for example.
Rick Ratayczak