예제 #1
0
        static void Main(string[] args)
        {
            // Initially ATM Machine in DebitCardNotInsertedState
            ATMMachine atmMachine = new ATMMachine();

            Console.WriteLine("ATM Machine Current state : "
                              + atmMachine.atmMachineState.GetType().Name);
            Console.WriteLine();
            atmMachine.EnterPin();
            atmMachine.WithdrawMoney();
            atmMachine.EjectDebitCard();
            atmMachine.InsertDebitCard();
            Console.WriteLine();
            // Debit Card has been inserted so internal state of ATM Machine
            // has been changed to DebitCardInsertedState
            Console.WriteLine("ATM Machine Current state : "
                              + atmMachine.atmMachineState.GetType().Name);
            Console.WriteLine();
            atmMachine.EnterPin();
            atmMachine.WithdrawMoney();
            atmMachine.InsertDebitCard();
            atmMachine.EjectDebitCard();
            Console.WriteLine("");
            // Debit Card has been ejected so internal state of ATM Machine
            // has been changed to DebitCardNotInsertedState
            Console.WriteLine("ATM Machine Current state : "
                              + atmMachine.atmMachineState.GetType().Name);
            Console.Read();
        }
예제 #2
0
        /*
         * Reference: YouTube/Derek Banas
         * Allows an object to alter it's behavior when it's internal state changes
         * Here, we're trying to achieve a situation where an action could be called in any state of the object and it should be well equiped to handle it.
         * For e.g. States like HasCard, NoCard, HasCash, NoCash etc. the ATM Machine could be either of the states, say HasCard - the next logical step would be add PIN which should be handled appropriately. However, if the requests cash directly, then this too should be handled properly.
         * Hence, we define an interface IState, all identified States are defined it and equal implementation class are instantiated.
         * In the ATM Machine class, we hold instances of these stated and vice versa.
         * We'll getter setter methos on ATM Machine for all properties and states.
         * This is a fool proof plan if all the states are identified and defined well.
         */
        static void Main(string[] args)
        {
            var atmMachine = new ATMMachine();

            atmMachine.insertCard();
            atmMachine.ejectCard();
            atmMachine.insertCard();
            atmMachine.insertPin(1234);
            atmMachine.requestCash(1500);
            atmMachine.insertCard();
            atmMachine.insertPin(1234);
        }
예제 #3
0
 public NoCash(ATMMachine newATMMachine)
 {
     atmMachine = newATMMachine;
 }
예제 #4
0
 public NoCash(ATMMachine atm)
 {
 }
예제 #5
0
 public HasCard(ATMMachine atm)
 {
     _atm = atm;
 }
예제 #6
0
 public HasCard(ATMMachine newATMMachine)
 {
     atmMachine = newATMMachine;
 }
예제 #7
0
 public HasPin(ATMMachine atm)
 {
     _atm = atm;
 }
예제 #8
0
 public HasPin(ATMMachine newATMMachine)
 {
     atmMachine = newATMMachine;
 }
예제 #9
0
 public NoCard(ATMMachine atm)
 {
     _atm = atm;
 }
예제 #10
0
 public HasNoCash(ATMMachine _aTMMachine)
 {
     aTMMachine = _aTMMachine;
 }
예제 #11
0
 public HasPin(ATMMachine _aTMMachine)
 {
     atmMachine = _aTMMachine;
 }
예제 #12
0
 public NoCard(ATMMachine _aTMMachine)
 {
     aTMMachine = _aTMMachine;
 }
예제 #13
0
 public hasCard(ATMMachine _atmMachine)
 {
     atmMachine = _atmMachine;
 }