This C# program is a simple banking application that follows the Interpreter Pattern. Let’s break down the key components and their functionalities:
-
Interpreter Pattern is a behavioral design pattern that defines a grammar for a language and provides an interpreter to interpret sentences in that language.
-
Expression.cs - Defines the Expression interface, which declares the Interpret method. This method will be implemented by concrete expression classes to perform operations on a bank account.
-
CheckBalanceExpression.cs - Implements the Expression interface. It interprets and displays the account balance on the console.
-
Context.cs - Represents the context in which an interpretation operation is performed. It holds an instance of the Account class.
-
DepositExpression.cs - Implements the Expression interface. It interprets and performs a deposit operation on the provided account, updating the balance.
-
WithdrawExpression.cs - Implements the Expression interface. It interprets and performs a withdrawal operation on the provided account, considering the balance and displaying appropriate messages.
-
Account.cs (Models) - Represents a bank account with a balance.
-
Program.cs - The main entry point for the banking application. It creates an account, a context for that account, and provides a simple console-based user interface to interact with the banking operations.
Key User Interactions:
- Check Balance (Option 1): Displays the account balance.
- Withdraw (Option 2): Allows the user to input an amount and withdraw funds if sufficient balance is available.
- Deposit (Option 3): Allows the user to input an amount and deposit funds.
- Exit (Option 4): Terminates the program.
How to Run:
- The program starts by creating an account and a context.
- It enters a loop where the user can choose options (1-4) to perform different banking operations.
- Depending on the option chosen, the program interacts with the corresponding expression classes to interpret and execute the requested operation on the account.
Example Flow:
- User chooses option 1: Check Balance.
- The CheckBalanceExpression is instantiated, and its Interpret method is called to display the account balance.