I have a symfony2 application which consist of a site, with many games.
So I have created a CoreBundle (the site), and a bundle for every games which interact with the core.
Games bundle interact with the core (update player score), and the core notifies games when something has changed and game should do something (for example a game instance has been created in the core, so the game should initialize data related to itself).
At this moment, I am hesitate between two architectural point of view.
Firstly, to do this, I created an interface that each games must implement. In this interface, many method are called at differents moments of the game workflow. That works, but it is not a very nice pattern, and methods in the interface are growing again and again, and even if I created an Adapter, that makes too many methods a game must implement.
Secondly, I so decided to use events to make the interface lighter, and a game can listen to some event triggered by the core.
That works too, and it is a good pattern, but another inconvenient comes to me:
Every game listen to a same event, so if a player creates a game instance of any game (then the core dispatch the event event.game.created
), every game is notified.
I can add a condition in every game listener method like if (game.name !== 'chess') return;
But I have too many game, and that makes too many methods called for nothing, for every event...
That is why I returned to the first method, call an interface method, then I am sure that the method of the good game bundle is called, and not all games methods when core notifies a game instance creation or any other event.
An inconvenient stays again:
I have many games, then many game bundles that are booted for nothing, because only core bundle and maybe one game bundle are used in a query.
Do you have some ideas or the same problem ?