Skip to main content

Practice ยท 3 of 3

Delegation Without Desync

AuditLog wraps a list and counts every entry ever added, even after removals (an audit trail must remember). Implement inside Solution: - static class AuditLog with methods add(String e), remove(String e) (removes first occurrence), int total() (entries ever added), and List<String> entries() (current content, unmodifiable). - Do NOT extend ArrayList. Compose and delegate โ€” the counting must stay correct even though remove() changes the visible size. The hidden test mimics the addAll bypass bug to prove composition wins.

Difficulty: intermediate

Back to lesson: Practice: Design Lab: Payments & Shapes