public interface Employee {
void work();
}
public class Junior implements Employee{
@Override
public void work() {
System.out.println("Junior is working");
}
}
public class Team implements Employee {
private final List<Employee> employees;
public Team(List<Employee> employees) {
this.employees = employees;
}
@Override
public void work() {
System.out.println("team is working start ---");
this.employees.forEach(Employee::work);
System.out.println("team is working end ---");
}
}
public class Client {
public static void main(String[] args) {
Employee junior1 = new Junior();
junior1.work();
Employee junior2 = new Junior();
junior2.work();
Employee team = new Team(List.of(junior1, junior2));
team.work();
}
}