Café POS — Design Patterns Lab
JavaMavenJaCoCo
A comprehensive Point-of-Sale system demonstrating 9 design patterns and layered architecture principles. Built incrementally across 10 weekly labs covering everything from basic domain modeling to event-driven architecture.
Quick Start
mvn compile
mvn test
# Expected: Tests run: 151, Failures: 0, Errors: 0, Skipped: 0
mvn test jacoco:report
# Coverage report: target/site/jacoco/index.html
# Expected: 85%+ on business logic Design Patterns Implemented
| Week | Pattern | Example |
|---|---|---|
| 3 | Decorator | ExtraShot, OatMilk, SizeLarge on products |
| 3 | Factory | ProductFactory.create("ESP+SHOT+OAT") |
| 4 | Strategy | CardPayment, CashPayment, WalletPayment |
| 4 | Observer | KitchenDisplay, CustomerNotifier, DeliveryDesk |
| 8 | Command | AddItemCommand with undo stack via PosRemote |
| 8 | Adapter | LegacyPrinterAdapter bridging old thermal printer |
| 9 | Composite | Menu / MenuItem hierarchy with depth-first traversal |
| 9 | Iterator | CompositeIterator over nested menu structure |
| 9 | State | OrderFSM: New → Preparing → Ready → Delivered |
Architecture (Week 10)
4-layer architecture with clean separation:
┌─────────────────────────────────────────────┐
│ Presentation Layer (UI) │
│ OrderController · ConsoleView │
├─────────────────────────────────────────────┤
│ Application Layer │
│ CheckoutService · EventBus (pub/sub) │
├─────────────────────────────────────────────┤
│ Domain Layer │
│ Order · LineItem · OrderFSM · Strategies │
├─────────────────────────────────────────────┤
│ Infrastructure Layer │
│ InMemoryOrderRepository · Wiring (DI) │
└─────────────────────────────────────────────┘ Dependencies point inward — Domain has no dependencies on other layers.
Test Coverage
| Component | Coverage |
|---|---|
| Payment Strategies | 100% |
| Pricing Service | 99% |
| State Pattern | 91% |
| Command Pattern | 91% |
| Week 10 Application | 100% |
| Week 10 Event Bus | 100% |
| Business logic overall | 85%+ |
151 tests, 0 failures.
Example Output
Order #4101
- Espresso + Extra Shot + Oat Milk x1 = 3.80
- Latte (Large) x2 = 7.80
Subtotal: 11.60
Discount: -0.58
Tax (10%): 1.10
Total: 12.12