concept

Through a exterior class, the interface of the whole system only has a unified high-level interface, so that the internal and external communication of the subsystem is carried out through a unified object, making the subsystem easier to use. (Actually many of the SDKS we use have it, such as Glide object for Glide, Picasso, etc.)

implementation

  • Facade – unified external interface object of the system
  • SystemA SystemB SystemC — Subsystem interface

For example, mobile phones (MobilePhone) are regarded as unified interfaces, with ordinary MobilePhone function subsystem (Phone) and Camera subsystem (Camera) inside.

public class MobilePhone {
    private Phone phone = new PhoneImpl();
    private Camera camera = new CameraImpl();

    public void call(){
        phone.call();
    }

    public void takephoto(){
        camera.tackphoto();
    }  
}

public interface Phone{
    void call();
}

public class PhoneImpl implements Phone {
    @Override
    public void call(){
        System.out.println("call");
    }
}

public interface Camera {
    void takephoto();
}

public class CameraImpl implements Camera {
    @Override
    public void takephoto(){
        System.out.println("takephoto"); }}Copy the code