Assume We Are Developing An Application That Enables A User To Control Lights And Other Electronics. We Are Exploring Possible Architectures With Code Samples Like The Following. Class Control Panel { LightOnCommand LightOnCmd; LightoffCommand LightoffCmd

匿名用户 最后更新于 2021-11-29 17:10 计算机类Computing

Assume we are developing an application that enables a user to control lights and other electronics. We are exploring possible architectures with code samples like the following. class Control Panel { LightOnCommand lightOnCmd; LightoffCommand lightoffCmd; public Control Panel (LightOnCommand lightOnCmd, LightOffCommand lightoffCmd) { this.lightOnCmd = lightOnCmd; this.lightoffCmd = lightoffCmd; } { public void onButton Pushed() lightOnCmd.execute(); } public void offButton Pushed() { lightoffCmd.execute(); class Light { public void on() { System.out.println("light on"); } public void off() { System.out.println("light off"); } class LightOnCommand { Light light; public LightOnCommand (Light light) { this.light = light; } public void execute() { light.on(); } } class LightOffCommand { Light light; public LightOffCommand (Light light) { this.light = light; } public void execute() { light.off();
class Maint public static Controlpanel loadRoomLightingConfigl () { Light roomLight = new Light(); LightOnCommand roomLightOnCmd = new LightOnCommand (roomLight); LightoffCommand roomLightoffCmd = new LightoffCommand (roomLight); Control Panel cp = new Controlpanel (roomLightOnCmd, roomLightoffCmd); return cp; } public static void runControl Panel Test (Control Panel cp, int times) { for (int i=0; i

已邀请: