O
O
Oxoron2015-02-04 15:34:06
.NET
Oxoron, 2015-02-04 15:34:06

What is the best way to convert a factory method?

Good afternoon.
There is a .NET program that implements a turn-based multiplayer game. It contains the Game class, with the GameStateChanged, GameEnded events.
The game is created like this:

CurrentGame = GameFactory.CreateGame(_gameMeta, activePlayer, true); 
CurrentGame.GameEnded += OnCurrentGameEnded;
CurrentGame.GameStateChanged += OnCurrentGameStateChaged;

_gameMeta - number of players, type (human\bot); activePlayer - index of the current player; true - create bots.
When playing with at least one person - everything is fine. When playing only bots, it makes no sense to subscribe to CurrentGame events. When creating a game, it immediately starts, and the connection to the event occurs after it (the game) ends. What is the best thing to do - throw out the launch of the game from the factory method, or pass delegates to it as arguments (optional), which it will attach to events?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mayorovp, 2015-02-04
@Oxoron

The correct way is to throw out the mandatory launch of the game. For example, by adding a named parameter with a default value.
Passing delegates to a factory method is already an extreme case, if it has come to this - it's time to change the architecture of the code, moving away from events.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question