I just reconstructed the scoring tactics of tennis to the state mode.
Process:
1) achieve simple scoring without leading (no AD) first, and reconstruct it to the state mode.
Tennis scoring
1.1) if the first player wins 4 points first, the player wins a game ).
1.2) scoring in each game is measured in a unique way in the tennis world: Winning 0, 1, 2, and 3 balls, with love, 15, 30, and 40 points respectively.
2) Consider scoring with leading conditions.
Tennis scoring
2.1) if the first player wins at least four points and at least two more matches than the opponent, the player wins a game ).
2.2) scoring in each game is measured in a unique way in the tennis world: Winning 0, 1, 2, and 3 balls, with love, 15, 30, and 40 points respectively.
2.3) if each contestant has won at least three balls and scored the same, each player is called "Deuce )".
2.4) if each contestant has already won at least three matches and one of them wins one more than the other, the contestant is called "advanced )".
The following are some experiences.
* 1) refactoring to a pattern is a little "carved" from the code without a pattern, driven by the pattern intent direction, rather than falsely dropping several classes in the pattern.
* 2) perform the following steps to refactor to the state mode:
* 2.1) First, use the if or switch statement to implement the business logic without considering the design mode.
* 2.2) create a context class and move the business logic to this place
* 2.3) create a State abstract class and delegate the business logic to the State abstract class by holding the State object in the context.
* 2.4) Implement specific business logic in the subclass of State to eliminate if or switch statements and save the next state to the state domain held by context, new status held as context