我想創建一個宏項目。這個宏項目將是可編輯的。哪個模式適用於具有依賴於其他屬性的兩個屬性
每個宏項目都有一個類型和一個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;'?這是一個非常糟糕的主意。你應該讓這個類不可變。 –