Answered step by step
Verified Expert Solution
Link Copied!

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:

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions

Question

2. Enrolling employees in courses and programs.

Answered: 1 week ago

Question

1. Communicating courses and programs to employees.

Answered: 1 week ago

Question

6. Testing equipment that will be used in instruction.

Answered: 1 week ago