Suppose I have an interface Employee and there are many classes that implement it, such as Bob, Joe, and Mary, none of which may be changed.
public interface Employee{
public void work()
}
public class Mary implements Employee{
public void work(){
//Mary's implementation of work
}
}
I must make a Manager class that is a wrapper for an Employee object. So the constructor for Manager takes an object of type Employee
Public class Manager{
private Employee employee;
public Manager(Employee employee){
this.employee = employee;
}
public void work(){
this.employee.work()
}
public void manage(){
//my implementation of manage
}
}
When a Manager object is instantiated, it should have all the methods of the underlying Employee plus a few extra. Most of the methods of the underlying Employee object will not be overridden (see work), and thus I think I should be extending Employee. But a class cannot extend an interface. Currently, I am working on declaring each of the Employee methods within the Manager class and having them simply call the corresponding Employee method. But that seems like unnecessary boilerplate and like it will break if the Employee interface ever changes.
Since extending an interface is not allowed, What is the correct design pattern for what I am trying to do?