我有一些在多个命令之间重复的数据。如何使用类对公共参数进行重复数据删除?如果我可以使用一个类,我也可以对其他代码进行重复数据删除。
下面提供的示例代码在我的两个命令之间重复了 common1 和 common2。
public class Job1 {
@Option(name="-common1",usage="common1")
public String common1;
@Option(name="-common2",usage="common2")
public String common2;
@Option(name="-somethingDifferent",usage="onlyJob1HasThis")
public String onlyJob1HasThis;
public void run() {
System.out.println("common1=" + common1);
System.out.println("common2=" + common2);
System.out.println("onlyJob1HasThis=" + onlyJob1HasThis);
CommonUtility.doSomethingCommon(common1, common2);
this.doSomethingDifferent(common1, common2);
}
}
public class Job1 {
@Option(name="-common1",usage="common1")
public String common1;
@Option(name="-common2",usage="common2")
public String common2;
@Option(name="-onlyJob2HasThis",usage="onlyJob2HasThis")
public String onlyJob2HasThis;
public void run() {
System.out.println("common1=" + common1);
System.out.println("common2=" + common2);
System.out.println("onlyJob2HasThis=" + onlyJob2HasThis);
CommonUtility.doSomethingCommon(common1, common2);
this.doSomethingDifferent(common1, common2);
}
}