Composition over inheritance
Java
Medium
5 views
Problem Description
Task: create Logger used inside Service (composition). Provide method logCount.
Output Format
Return value
Constraints
Do not use static global state.
Official Solution
static class Logger{private int c;void log(){c++;}int count(){return c;}}static class Service{private final Logger l=new Logger();void doWork(){l.log();}int logCount(){return l.count();}}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!