Facebook Pixel

Exercise: Facade

This exercise puts the Facade pattern into code.

Scenario

A home theater system has four independent subsystems: Lights, Screen, Projector, and SoundSystem. Each subsystem exposes simple methods that return a string describing the action it just performed. A HomeTheaterFacade sits in front of them and exposes two high-level operations — watch to start a movie and end to shut everything down — so callers never need to know the subsystem order or method names.

Commands

CommandBehaviorOutput
["watch"]Start a movie: dim lights, lower screen, turn on projector, turn on soundfour lines, one per subsystem action, in order
["end"]Shut down: turn off projector, turn off sound, raise screen, turn on lightsfour lines, one per subsystem action, in order
Example
Input
2
watch
end
Output
Lights: dim to 10%
Screen: down
Projector: on
Sound: on at volume 8
Projector: off
Sound: off
Screen: up
Lights: on
Explanation
The `watch` command coordinates four subsystems in order and emits one line per action: the lights dim, the screen lowers, the projector turns on, and the sound turns on. The `end` command reverses the process: the projector turns off, the sound turns off, the screen raises, and the lights turn back on. Both commands produce four lines each.

Your task

Create the HomeTheaterFacade class so the commands produce the output above. The starter keeps all four subsystem classes (Lights, Screen, Projector, SoundSystem) and the run_theater dispatcher, and marks where to add HomeTheaterFacade with a TODO comment listing its constructor signature, the watch method (which calls the subsystems in the documented order and returns the lines), and the end method (which does the same for shutdown).

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro