The Facade Pattern exposes several components through a single interface. The goal is to simplify the API for the client components.
Let’s say we want to make a robot. A robot is made out of different parts. Our code may look like:
public class SimpleArm implements Arm {
public SimpleArm() {
}
}
public class Robot {
private Arm arm;
public Robot(Arm arm) {
this.arm = arm;
}
public void moveArm() {
...
}
}
Now this code looks simple, but it could be more complex if the Arm is complicated to be instantiated… and if we add more parts to our robots that are configurable. And we can even have a complex robot made of other robots. Instead of forcing the client code to create the different parts and “assemble” them in the Robot class, we can offer a facade class that requires only a few parameters, instantiate the different parts and offer simple methods to move the robot. The only disadvantage is the possible lack of flexibility for optimization and specification.