An interactive command-line application demonstrating the Strategy design pattern through simulated payment methods.
- Select multiple colors, sizes, and fabrics.
- Validate that each selection contains at least one option.
- Choose credit/debit card, bank transfer, or cash.
- Execute only the selected payment strategy.
- Handle cancellation gracefully.
- Run locally or with Docker.
- Colored terminal banner and step-by-step menus.
- Formatted selection summary using Rich.
- Confirmation before running the payment demo.
- Start another selection without restarting the application.
This is an educational demo. No real payments are processed.
Selections are lists of preferences. The application does not calculate prices, quantities, or individual product combinations.
PaymentStrategy defines the common pay() interface.
CardPayment, BankTransferPayment, and CashPayment
implement that interface.
PaymentContext delegates execution to its selected strategy.
The strategy can be replaced through set_strategy().
The CLI selects the strategy after the user chooses a payment method.
app.py: interactive menus and application entry point.payments.py: payment strategies and context.requirements.txt: Python dependencies.Dockerfile: container image definition.docker-compose.yml: interactive container configuration.init.sh: optional Linux/macOS launcher.
Use Python 3.11 for consistency with the Docker image.
From the project root:
py -3.11 -m venv venv
.\venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
python app.pyPython 3.11 must be installed for the py -3.11 command.
For Windows Command Prompt, activate with:
venv\Scripts\activate.batWith Python 3.11 installed:
python3.11 -m venv venv
source venv/bin/activate
python -m pip install -r requirements.txt
python app.pyInstall Docker with Docker Compose support, then run:
docker compose run --build --rm pythonTo run the existing image again:
docker compose run --rm pythonRebuild after changing application code or dependencies.
- Arrow keys: navigate.
- Space: toggle checkbox selections.
- Enter: continue.
- Ctrl+C: cancel.
Run the application in a terminal, such as the VS Code integrated terminal, PowerShell, or a Linux/macOS terminal.