A Facade is a simple interface in front of a complex subsystem. Instead of knowing many classes and the right order of calls, the client calls one or two high-level methods. The subsystem is unchanged; the facade only coordinates it.
The problem: many parts and a fixed order
A home theater consists of lights, a projector, an amplifier and a player. Starting a movie needs a specific sequence of calls on all four. Without a facade every client repeats the sequence, and every repetition can get the order wrong.
class Lights:
def dim(self, level):
print(f"lights {level}%")
class Projector:
def on(self):
print("projector on")
def off(self):
print("projector off")
class Amp:
def on(self):
print("amp on")
def off(self):
print("amp off")
def volume(self, v):
print(f"amp volume {v}")
class Player:
def play(self, movie):
print(f"playing {movie}")
def stop(self):
print("player stopped")
lights, projector, amp, player = Lights(), Projector(), Amp(), Player()
lights.dim(10) # the client must know all steps and their order
projector.on()
amp.on()
amp.volume(7)
player.play("Dune")lights 10%
projector on
amp on
amp volume 7
playing Dune