Skip to main content

Practice · 3 of 3

Delegation Without Desync

CHALLENGE
Difficulty: intermediate+25 XP

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.

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