Let's use a trait to separate the callback handling from the button logic.
让我们对按钮的逻辑来使用trait,从而分离回调的处理。
The logic for the type of button and the event handler to be invoked is contained in this method, shown in Listing 15.
被调用的按钮和事件处理程序的类型的逻辑包含在此方法中,如清单 15 所示。
We had to duplicate that logic in ButtonObserverAnonSpec when we declared observableButton as a Button instance that mixed in the Subject trait directly.
而我们在声明observablebutton为一个按钮实例的时候,我们直接混合了Subject trait,它重复了ButtonObserverAnonSpec的逻辑。
应用推荐