1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
namespace ConsoleApplication2 { class Program { static void Main(string[] args) { } } /* State 状態管理のクラス */ public class Context//具体的な状態(ConcreateState)を保持する。 { public State state; public void ChangeState(State state) { this.state = state; } public void Action() { this.state.Action(); } } public interface State//状態を表すクラス { void Action(); } public class ConcreateState1: State//具体的な状態 { public void Action() { //状態1 } } public class ConcreateState2 : State//具体的な状態 { public void Action() { //状態2 } } } |