🪟 Windows TippsModify Windows Support Phone Number with PowerShell(03.09.2026 um 00:00 Uhr)
🔧 AI Nachrichten Podcast: ChatGPT schwatzt Nutzern in Deutschland jetzt Werbung auf(28.08.2026 um 08:46 Uhr)
🪟 Windows TippsMicrosoft bringt Emoji 17.0 auf Windows 11(31.08.2026 um 08:16 Uhr)
🪟 Windows TippsModify Windows Support Phone Number with PowerShell(03.09.2026 um 00:00 Uhr)
🔧 AI Nachrichten Podcast: ChatGPT schwatzt Nutzern in Deutschland jetzt Werbung auf(28.08.2026 um 08:46 Uhr)
🪟 Windows TippsMicrosoft bringt Emoji 17.0 auf Windows 11(31.08.2026 um 08:16 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 3 Min Lesezeit
0

Facade Pattern

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




What is Facade Pattern?




Facade pattern is a structural pattern that provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.







When to use it?



Use Facade pattern when you need simplified interface that orchestrates many classes and does the complex work.






Problem



Our company is going to sell a car. To start driving, a client needs to follow these procedure...




  1. unlock the door

  2. open the door

  3. start engine

  4. turn on the dashboard

  5. turn on the navigation screen

  6. if outside is dark, turn on the headlight

  7. close the door

  8. lock the door



Even a client hasn't pedal yet, there are already 8 steps.

How would it be in OOP? In fact, we need 5 different classes and 8 methods calls.




CODE
        door.unlock();
door.open();
engine.start();
dashBoard.on();
screen.on();
if (isOutsideDark) {
light.on();
}
door.close();
door.lock();






The question is, is there a easier way for a client to deal with tasks such as starting driving, stopping driving and so on? Yes, there is Facade pattern.






Solution








Implementation in Java



Implementing subsystem classes is not important to explain Facade pattern, so I omit these parts but you can check in my Github at the end of this blog.




CODE
public class CarFacade {

private DashBoard dashBoard;
private Door door;
private Engine engine;
private HeadLight light;
private NavigationScreen screen;

private boolean isOutsideDark;

public CarFacade(DashBoard dashBoard,
Door door,
Engine engine,
HeadLight light,
NavigationScreen screen,
boolean isOutsideDark) {
this.dashBoard = dashBoard;
this.door = door;
this.engine = engine;
this.light = light;
this.screen = screen;
this.isOutsideDark = isOutsideDark;
}

public void startDriving() {
door.unlock();
door.open();
engine.start();
dashBoard.on();
screen.on();
if (isOutsideDark) {
light.on();
}
door.close();
door.lock();
}

public void endDriving() {
light.off();
screen.off();
dashBoard.off();
engine.stop();
door.unlock();
door.open();
}
}









CODE
public class Client {

public static void main(String[] args) {
// Create components
DashBoard dashBoard = new DashBoard();
Door door = new Door();
Engine engine = new Engine();
HeadLight light = new HeadLight();
GPS gps = new GPS();
NavigationScreen screen = new NavigationScreen(gps);

// Instantiates Facade with all the components in the subsystem
CarFacade automatedCar = new CarFacade(dashBoard, door, engine, light, screen, true);

// Use the simplified interface to start and end driving
automatedCar.startDriving();
System.out.println();
automatedCar.endDriving();
}
}






Output:




CODE
Unlock the door
Open the door
Start Engine
DashBoard displays speed: 60km/h, fuel remaining: 70%
Navigation screen displays gps: 43.01787, -76.216435
HeadLight is on
Close the door
Lock the door

HeadLight is off
Navigation screen is off
DashBoard is off
Stop Engine
Unlock the door
Open the door









Pitfalls




  • There is no really known pitfall to Facade.






Comparison with Adapter Pattern




  • Adapter pattern introduces new interface to adapt incompatible interface to the interface the client expects, while Facade pattern creates unified interface that makes subsystem easier to use.






You can check all the design pattern implementations here.

GitHub Repository

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Modify Windows Support Phone Number with PowerShell
1 Quelle
Die Zukunft des Einkaufens: Warum wir ein neues Kapitel aufschlagen (und wie du es mitschreiben kannst)
1 Quelle
ZDE Podcast 251: Wie sieht digitales Instore Marketing 2026 aus, Amit Chatterjee?
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Facade Pattern

Thematisch verwandte Begriffe: Facade, Pattern · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...