Question: Design: users can control lights and other electronics. Open/Close principle: want to be able to add new features without having to rewrite (modify) existing code.

Design: users can control lights and other electronics.

Open/Close principle: want to be able to add new features without having to rewrite (modify) existing code.

Code:

Design: users can control lights and other electronics. Open/Close principle: want to

be able to add new features without having to rewrite (modify) existing

Describe the application with respect to the Open-Closed Principle. Specifically, what would be the impact of adding a new electronic (e.g., security camera) to the control panel? Be specificabout what aspects of the application follow or violate the Open-Closed Principle.

class Control Panel { LightOnCommand lightOnCmd; LightoffCommand lightoffCmd; public Controlpanel (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 Main { public static Control Panel loadRoomLightingConfigi () { Light roomLight = new Light(); LightOnCommand roomLightOnCmd = new LightOnCommand (roomLight); LightoffCommand roomLightoffCmd = new LightoffCommand (roomLight); Controlpanel cp = new Control Panel (roomLightOnCmd, roomLightoffCmd); return cp; } public static void runControlpanelTest (Controlpanel cp, int times) { for (int i=0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!