【发布时间】:2012-09-26 11:04:10
【问题描述】:
我有一个类BaseClass,其中包含一些方法,例如
public Result mothodA(Token token, String arg1, String arg2);
public Result mothodB(Token token, String arg1);
public OtherResult mothodC(Token token, String arg1, String arg2);
...
是否可以以某种方式装饰此类以自动传递Token 参数(将存储在装饰器中)?
预期输出:
DecoratedBaseClass decorated = new DecoratedBaseClass();
Result result = decorated.methodA("arg1", "arg2");
OtherResult otherResult = decorated.methodC("arg1", "arg2");
我打赌这是不可能的,但也许我不知道装饰器的一些技巧。
【问题讨论】:
-
你可以有一个带Token的构造函数吗?
-
我现在无法修改
BaseClass- 它是使用 WSDL 文件生成的。我将在DecoratedBaseClass构造函数中创建Token对象。