DEV Community

eidher
eidher

Posted on • Edited on

2

Facade Pattern

Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.

Alt Text

Participants

  • Facade: knows which subsystem classes are responsible for a request. Delegates client requests to appropriate subsystem objects.
  • Subsystem classes: implement subsystem functionality. Handle work assigned by the Facade object. Have no knowledge of the facade and keep no reference to it.

Code

public class Main {

    public static void main(String[] args) {
        Facade facade = new Facade();
        facade.methodA();
        facade.methodB();
    }
}

public class SubSystemOne {
    public void methodOne() {
        System.out.println(" SubSystemOne Method");
    }
}

public class SubSystemTwo {
    public void methodTwo() {
        System.out.println(" SubSystemTwo Method");
    }
}

public class SubSystemThree {
    public void methodThree() {
        System.out.println(" SubSystemThree Method");
    }
}

public class SubSystemFour {
    public void methodFour() {
        System.out.println(" SubSystemFour Method");
    }
}

public class Facade {

    private SubSystemOne one;
    private SubSystemTwo two;
    private SubSystemThree three;
    private SubSystemFour four;

    public Facade() {
        one = new SubSystemOne();
        two = new SubSystemTwo();
        three = new SubSystemThree();
        four = new SubSystemFour();
    }

    public void methodA() {
        System.out.println("\nmethodA() ---- ");
        one.methodOne();
        two.methodTwo();
        four.methodFour();
    }

    public void methodB() {
        System.out.println("\nmethodB() ---- ");
        two.methodTwo();
        three.methodThree();
    }
}
Enter fullscreen mode Exit fullscreen mode

Output

methodA() ---- 
 SubSystemOne Method
 SubSystemTwo Method
 SubSystemFour Method

methodB() ---- 
 SubSystemTwo Method
 SubSystemThree Method
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more