我想创建一个宏项目。这个宏项目将是可编辑的。哪个模式适用于具有依赖于其他属性的两个属性
每个宏项目都有一个类型和一个eventValue。
有三类项目(pressKey,releaseKey,delayInMs)
对于pressKeyEvent,我想的是,用户只能选择一个作为keyObject的eventValue的releaseKeyEvent。
对于delayEvent,我希望用户只能选择一个整数作为eventValue。
现在我有这个
export enum MacroEventEnum {
pressKey,
releaseKey,
delayInMs
}
export class MacroItem {
// This represent the type of the macro event
public macroEvent: MacroEventEnum;
// This represent the value associate with the macro event
public macroEventValue: any;
constructor(macroEvent: MacroEventEnum, macroEventValue: any) {
this.macroEvent = macroEvent;
this.macroEventValue = macroEventValue;
}
}
的问题是,当用户改变macroEvent的类型是pressKey,它仍然可以使用的时间内macroEventValue。
在这种情况下应该使用什么样的模式知道用户可以随时更改macroEvent。
感谢您的建议:)
“知道用户可以随时更改itemEvent”是什么意思?另外,这功课呢? –
更精确吗? @AlexHall – stephanec
我不知道这是什么语言,所以我会假装它是Java。你打算让用户写'MacroItem item = new MacroItem(pressKey,enterKey); item.macroEvent = delayInMs;'?这是一个非常糟糕的主意。你应该让这个类不可变。 –