Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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:
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; iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started