Symfony2 design pattern: EventDispatcher - mediator or event aggregator?

From the Symfony2 EventDispatcher component documentation:

Symfony2's EventDispatcher component implements the Mediator template in a simple and effective way to make it all possible and make your projects truly extensible.

I read about Event Aggregator and reseller templates and their differences . For me, it looks like Event Aggregator is a specific case of an intermediary that uses events to facilitate communication and does not have any business logic inside. The intermediary, on the other hand, is more general and can allow a certain business logic to decide whether a certain communication should take place.

So, I checked the source code for the Symfony2 EventDispatcher or TraceableEventDispatcher and found that the only logic that could change the connection was to check if the event propagation was stopped, as follows:

protected function doDispatch($listeners, $eventName, Event $event)
{
    foreach ($listeners as $listener) {
        call_user_func($listener, $event, $eventName, $this);
        if ($event->isPropagationStopped()) {
            break;
        }
    }
}

This is why EventDispatcher in Symfony2 implements a mediator template, but not an event aggregator template? If the logic for verification is isPropagationStoppedtransferred from the EventDispatcher (say, to event listeners), then will this implement an event aggregator?

+4
source share
1 answer

An Event Aggregator is similar to an Observer pattern, Subject simply notifies Observer objects that there are changes that need to be updated no matter what event it has.

Symfony2 EventDispatcher , , , , . , isPropagationStopped, EventDispatcher - , , .

,

+3

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


All Articles