开发者

Code generation for composition using Eclipse

开发者 https://www.devze.com 2022-12-12 02:58 出处:网络
Effective Java, along with other sources suggest thatwe should consider using composition over inheritance. I have often found my self achieving such composition by using the Decorator pattern and imp

Effective Java, along with other sources suggest that we should consider using composition over inheritance. I have often found my self achieving such composition by using the Decorator pattern and implementing forwarding methods that delegate invocations to a wrapped object.

However, I often find myself writing many simple forwarding methods of the type:

public开发者_开发问答 void myMethod(String name) {
    instance.myMethod(name);
}

Is there anyway of auto-generating these forwarding methods within Eclipse (3.4.x)?


In the Source menu choose "Generate Delegate Methods". It will give you a list of methods available on any of your fields that you can have the current object forward to.


You could write a custom template (Window > Preferences > filter on "Template") that has a placeholder for the method name and parameter name.

0

精彩评论

暂无评论...
验证码 换一张
取 消