This project demonstrates the Factory Design Pattern using a banking application example in C#.
The Factory Design Pattern is a creational pattern that provides an interface for creating objects without specifying their exact classes. It centralizes object creation logic and enables loose coupling between client code and concrete implementations.
- IAccount.cs - Common interface for all account types
- AccountType.cs - Enumeration defining available account types
- SavingsAccount.cs - Savings account implementation
- CheckingAccount.cs - Checking account implementation
- BusinessCheckingAccount.cs - Business checking account implementation
- AccountFactory.cs - Factory class responsible for creating account instances
- Program.cs - Client application demonstrating pattern usage
- Centralized object creation - All instantiation logic in one place
- Loose coupling - Clients depend only on interfaces
- Easy extensibility - New account types can be added without modifying client code
- Interface-based design - Client code works exclusively with interfaces
- Navigate to the project directory
- Run
dotnet runto execute the application
To add a new account type:
- Create a new class implementing
IAccount - Add the new type to the
AccountTypeenum - Update the factory's switch statement
- No client code modification required!
This demonstrates the pattern's strength in supporting extensible design.