Imagine you have to wrap an instance of a java.sql.ResultSet. You can’t extend it because you don’t know what is the concrete class implementing ResultSet being actually instantiated. You can just aggregate the instance, implement ResultSet and override all the methods.
Now imagine you want to change the behavior of just one method. All the other overridden methods are just a long boilerplate like this:
public void foo() {
wrapped.foo();
}
Do you know any automatic code-generation tool that can perform this job for me (either standalone or included into common IDEs)?
In Eclipse, create a class with the ResultSet as a member, put the cursor on this member and then choose the menu “Source > Generate delegate Methods”.
Check the methods you want to generate delegates for and it’s done.