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

WeekPatternExample
3DecoratorExtraShot, OatMilk, SizeLarge on products
3FactoryProductFactory.create("ESP+SHOT+OAT")
4StrategyCardPayment, CashPayment, WalletPayment
4ObserverKitchenDisplay, CustomerNotifier, DeliveryDesk
8CommandAddItemCommand with undo stack via PosRemote
8AdapterLegacyPrinterAdapter bridging old thermal printer
9CompositeMenu / MenuItem hierarchy with depth-first traversal
9IteratorCompositeIterator over nested menu structure
9StateOrderFSM: 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

ComponentCoverage
Payment Strategies100%
Pricing Service99%
State Pattern91%
Command Pattern91%
Week 10 Application100%
Week 10 Event Bus100%
Business logic overall85%+

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