In the game I'm developing I need to determine if an action is possible. Whether the action is possible is dependent on a number of factors spread across many objects (ActionDeterminers) in the game. These objects may or may not exist, and whether each of the objects allows the action is dynamic.
I had the idea to implement an Observer-style pattern, where these ActionDeterminers can register themselves with a Subject. When the Subject is asked
IsActionPossibleEverywhere, it can then call an interface function on each of the ActionDeterminers:
IsActionPossible, and then AND all of their results. Is there a name for this pattern?
The issue I'm facing is that I would also like to notify another set of objects (Observers) of changes in the result of
IsActionPossibleEverywhere, using the standard Observer pattern. As far as I can tell, I have two options for this:
Polling. I could simply call
IsActionPossibleEverywherein the main loop, and then notify every Observer when the the result changes from the last call. Unfortunately, the
IsActionPossibleEverywherecall could potentially be non-performant (depending on each of the ActionDeterminers).
Give each of the ActionDeterminers the additional responsibility of informing the Subject of when their personal
IsActionPossiblecall might change. The Subject will then call
IsActionPossibleEverywhereand inform its Observers if the result changed from the last call. This is considerably more complex and has more potential points of failure.