Every small event posted in an event aggregator should be empty by its own CompositePresentationEvent?

I am trying to understand an event aggregator pattern in terms of architecture and design. I have never used Prism in WPF before, but I am learning how it works on MSDN.

It seems to me that for each event, the user should create a new event object that extends CompositePresentationEvent . It also seems that the new event object has no functions other than those for which it has inherited (it usually does not have code for itself).

So for example:

A AddNewStuffEvent will look like this:

 public class AddNewStuffEvent : CompositePresentationEvent<Object> {} //The end of the class 

With a HealthChangeEvent :

 public class HealthChangeEvent: CompositePresentationEvent<Object> {} //The end of the class 

With a BookFlipEvent :

 public class BookFlipEvent: CompositePresentationEvent<Object> {} //The end of the class 

With a BookCloseEvent :

 public class BookCloseEvent: CompositePresentationEvent<Object> {} //The end of the class 

And this can go on forever for every little little event for BookOpenEvent , BookTearEvent , etc. Thus, in a particular namespace folder there will be a whole ton of event classes, and the event aggregator will load with all these event objects at run time. That is, every little little event needs an empty class? Does this work? What could be the best way to do this?

+4
source share
1 answer

Yes, each type of event requires its own class, which you must define.

It also seems that the new event object has no function other than those that it inherited from

The goal is to provide strong typing for the event. This makes it easy to write code to subscribe to them. Those. The subscription code can be written as follows:

 aggregator.GetEvent<AddNewStuffEvent>().Subscribe(Handler); 

This is the preferred approach to alternatives, such as dependency on β€œmagic strings” in the form of say aggregator.GetEvent("AddNewStuffEvent").Subscribe(Handler) (which cannot be checked at compile time.

+3
source

Source: https://habr.com/ru/post/1441050/


All Articles