From 8c137f229c36a777ead5cacb3350cb8692646292 Mon Sep 17 00:00:00 2001 From: "mo.khan" Date: Sat, 5 Jan 2008 07:16:52 +0000 Subject: git-svn-id: http://mokhan.googlecode.com/svn/trunk@9 a0a4a051-f042-0410-9e78-9fae330bdb64 --- .../ProcessingTransactionState.cs | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 DesignPatterns/src/app/DesignPatterns.State/ProcessingTransactionState.cs (limited to 'DesignPatterns/src/app/DesignPatterns.State/ProcessingTransactionState.cs') diff --git a/DesignPatterns/src/app/DesignPatterns.State/ProcessingTransactionState.cs b/DesignPatterns/src/app/DesignPatterns.State/ProcessingTransactionState.cs new file mode 100644 index 0000000..f91cae4 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.State/ProcessingTransactionState.cs @@ -0,0 +1,37 @@ +using System; + +namespace DesignPatterns.State { + internal class ProcessingTransactionState : IState { + public ProcessingTransactionState( IPosTerminal terminal ) { + _terminal = terminal; + } + + public void ProcessTransaction( ) { + if ( (++_counter % 5) == 0 ) { + _terminal.CurrentState = new TransactionRejectedState( _terminal ); + } + else { + _terminal.CurrentState = new TransactionApprovedState( _terminal ); + } + } + + public void PrintReceipt( ) { + Console.Out.WriteLine( "The transaction needs to be processed first" ); + } + + public void SwipeCard( string cardNumber ) { + Console.Out.WriteLine( "You have already swiped a card" ); + } + + public void EnterAmount( double amount ) { + Console.Out.WriteLine( "You have already entered an amount" ); + } + + public void EnterPin( string pin ) { + Console.Out.WriteLine( "You have already entered a PIN" ); + } + + private readonly IPosTerminal _terminal; + private static int _counter; + } +} \ No newline at end of file -- cgit v1.2.3