【发布时间】:2022-12-06 08:47:45
【问题描述】:
`我一直在研究构建器模式,在将代码从 Java 编写到 Apex 时遇到了问题。它适用于 Java,但在 Apex 上出现问题
这是我的 Apex - 课程。
`public class Chiller {
private double coolingCapacity;
private double compressorPower;
private double EER;
RefrigerationType refrigerationType;
public void setCoolingCapacity(double coolingCapacity) {
this.coolingCapacity = coolingCapacity;
}
public void setCompressorPower(double compressorPower) {
this.compressorPower = compressorPower;
}
public void setEER(double EER) {
this.EER = EER;
}
public void setRefrigerationType(RefrigerationType refrigerationType) {
this.refrigerationType = refrigerationType;
}
public override String toString() {
return 'Chiller [Cooling capacity = ' + coolingCapacity + ' compressor power input = ' + compressorPower + ' EER = ' + Math.round(EER) +
' refrigeration type is ' + refrigerationType + ']';
}
}
公共枚举 RefrigerationType {R134, R12}
public abstract class ChillerBuilder {
Chiller chiller;
public void createChiller() {
chiller = new Chiller();
}
public abstract void buildCapacity();
public abstract void buildCompressorPower();
public abstract void buildEER();
public abstract void buildRefrigerationType ();
Chiller getChiller() {
return chiller;
}
}
public class ScrewBuilder extends ChillerBuilder {
public override void buildCapacity() {
chiller.setCoolingCapacity(((12-7)*1042*1000/3600));
}
public override void buildCompressorPower() {
chiller.setCompressorPower(((12-7)*1042*1000/3600)*0.83);
}
public override void buildEER() {
chiller.setEER(((12-7)*1042*1000/3600)/(((12-7)*1042*1000/3600)*0.83));
}
public override void buildRefrigerationType() {
chiller.setRefrigerationType(RefrigerationType.R134);
}
}
public class Director {
ChillerBuilder builder;
void setBuilder(ChillerBuilder b) {
builder = b;
}
Chiller BuildChiller() {
builder.createChiller();
builder.buildCapacity();
builder.buildCompressorPower();
builder.buildEER();
builder.buildRefrigerationType();
Chiller chiller = builder.getChiller();
return chiller;
}
}`
问题似乎在 ScrewBuilder 中,类变量与设置器不可见 chiller.setCoolingCapacity(((12-7)10421000/3600)); 你能帮我吗? 提前致谢!`
I tried to re-write access fields to public everywhere but it doesn't help
【问题讨论】:
标签: java salesforce apex builder-pattern