mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-06-02 18:13:50 +00:00
docs: Content SEO updates (#2990)
* update yaml frontmatter format * update abstract document * update abstract factory * use the new pattern template * acyclic visitor seo * adapter seo * ambassador seo * acl seo * aaa seo * async method invocation seo * balking seo * bridge seo * builder seo * business delegate and bytecode seo * caching seo * callback seo * chain seo * update headings * circuit breaker seo * client session + collecting parameter seo * collection pipeline seo * combinator SEO * command seo * cqrs seo * commander seo * component seo * composite seo * composite entity seo * composite view seo * context object seo * converter seo * crtp seo * currying seo * dao seo * data bus seo * data locality seo * data mapper seo * dto seo * decorator seo * delegation seo * di seo * dirty flag seo * domain model seo * double buffer seo * double checked locking seo * double dispatch seo * dynamic proxy seo * event aggregator seo * event-based asynchronous seo * eda seo * event queue seo * event sourcing seo * execute around seo * extension objects seo * facade seo * factory seo * factory kit seo * factory method seo * fanout/fanin seo * feature toggle seo * filterer seo * fluent interface seo * flux seo * flyweight seo * front controller seo * function composition seo * game loop seo * gateway seo * guarded suspension seo * half-sync/half-async seo * health check seo * hexagonal seo * identity map seo * intercepting filter seo * interpreter seo * iterator seo * layers seo * lazy loading seo * leader election seo * leader/followers seo * lockable object seo * rename and add seo for marker interface * master-worker seo * mediator seo * memento seo * metadata mapping seo * microservice aggregator seo * api gw seo * microservices log aggregration seo * mvc seo * mvi seo * mvp seo * mvvm seo * monad seo * monitor seo * monostate seo * multiton seo * mute idiom seo * naked objects & notification seo * null object seo * object mother seo * object pool seo * observer seo * optimistic locking seo * page controller seo * page object seo * parameter object seo * partial response seo * pipeline seo * poison pill seo * presentation model seo * private class data seo * producer-consumer seo * promise seo * property seo * prototype seo * proxy seo * queue-based load leveling seo * reactor seo * registry seo * repository seo * RAII seo * retry seo * role object seo * saga seo * separated interface seo * serialized entity seo * serialized lob seo * servant seo * server session seo * service layer seo * service locator seo * service to worker seo * sharding seo * single table inheritance seo * singleton seo * spatial partition seo * special case seo * specification seo * state seo * step builder seo * strangler seo * strategy seo * subclass sandbox seo * table module seo * template method seo * throttling seo * tolerant reader seo * trampoline seo * transaction script seo * twin seo * type object seo * unit of work seo * update method seo * value object seo * version number seo * virtual proxy seo * visitor seo * seo enhancements * seo improvements * SEO enhancements * SEO improvements * SEO additions * SEO improvements * more SEO improvements * rename hexagonal + SEO improvements * SEO improvements * more SEO stuff * SEO improvements * SEO optimizations * SEO enhancements * enchance SEO * improve SEO * SEO improvements * update headers
This commit is contained in:
+27
-20
@@ -1,23 +1,25 @@
|
||||
---
|
||||
title: Facade
|
||||
title: "Facade Pattern in Java: Simplifying Complex System Interfaces"
|
||||
shortTitle: Facade
|
||||
description: "Learn how to implement the Facade Design Pattern in Java to create a unified interface for complex subsystems. Simplify your code and enhance maintainability with practical examples and use cases."
|
||||
category: Structural
|
||||
language: en
|
||||
tag:
|
||||
- Abstraction
|
||||
- API design
|
||||
- Code simplification
|
||||
- Decoupling
|
||||
- Encapsulation
|
||||
- Gang Of Four
|
||||
- Interface
|
||||
- Object composition
|
||||
- Abstraction
|
||||
- API design
|
||||
- Code simplification
|
||||
- Decoupling
|
||||
- Encapsulation
|
||||
- Gang Of Four
|
||||
- Interface
|
||||
- Object composition
|
||||
---
|
||||
|
||||
## Intent
|
||||
## Intent of Facade Design Pattern
|
||||
|
||||
Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
|
||||
The Facade Design Pattern provides a unified interface to a set of interfaces in a subsystem. This Java design pattern simplifies complex system interactions.
|
||||
|
||||
## Explanation
|
||||
## Detailed Explanation of Facade Pattern with Real-World Examples
|
||||
|
||||
Real-world example
|
||||
|
||||
@@ -31,7 +33,9 @@ Wikipedia says
|
||||
|
||||
> A facade is an object that provides a simplified interface to a larger body of code, such as a class library.
|
||||
|
||||
**Programmatic Example**
|
||||
## Programmatic Example of Facade Pattern in Java
|
||||
|
||||
Here's an example of the Facade Design Pattern in a goldmine scenario, demonstrating how a Java facade can streamline complex operations.
|
||||
|
||||
How does a goldmine work? "Well, the miners go down there and dig gold!" you say. That is what you believe because you are using a simple interface that goldmine provides on the outside, internally it has to do a lot of stuff to make it happen. This simple interface to the complex subsystem is a facade.
|
||||
|
||||
@@ -195,30 +199,33 @@ Program output:
|
||||
06:07:20.678 [main] INFO com.iluwatar.facade.DwarvenMineWorker -- Dwarven tunnel digger goes to sleep.
|
||||
```
|
||||
|
||||
## Applicability
|
||||
## When to Use the Facade Pattern in Java
|
||||
|
||||
Use the Facade pattern when
|
||||
Use the Facade pattern in Java when:
|
||||
|
||||
* You want to provide a simple interface to a complex subsystem.
|
||||
* Subsystems are getting more complex and depend on multiple classes, but most clients only need a part of the functionality.
|
||||
* There is a need to layer your subsystems. Use a facade to define an entry point to each subsystem level.
|
||||
* You want to reduce dependencies and enhance code readability in Java development.
|
||||
|
||||
## Tutorials
|
||||
## Facade Pattern Java Tutorials
|
||||
|
||||
* [Facade Design Pattern in Java (DigitalOcean)](https://www.digitalocean.com/community/tutorials/facade-design-pattern-in-java)
|
||||
* [Facade (Refactoring Guru)](https://refactoring.guru/design-patterns/facade)
|
||||
* [Facade Method Design Pattern (GeekforGeeks)](https://www.geeksforgeeks.org/facade-design-pattern-introduction/)
|
||||
* [Design Patterns - Facade Pattern (TutorialsPoint)](https://www.tutorialspoint.com/design_pattern/facade_pattern.htm)
|
||||
|
||||
## Known Uses
|
||||
## Real-World Applications of Facade Pattern in Java
|
||||
|
||||
* Java libraries such as java.net.URL and javax.faces.context.FacesContext use Facade to simplify complex underlying classes.
|
||||
* In many Java frameworks, facades are used to simplify the usage of APIs by providing a simpler interface to more complex underlying code structures.
|
||||
|
||||
## Consequences
|
||||
## Benefits and Trade-offs of Facade Pattern
|
||||
|
||||
Benefits:
|
||||
|
||||
Implementing the Facade Design Pattern in Java:
|
||||
|
||||
* Isolates clients from subsystem components, making it easier to use and reducing dependencies.
|
||||
* Promotes weak coupling between the subsystem and its clients.
|
||||
* Often simplifies the API of complex systems.
|
||||
@@ -227,12 +234,12 @@ Trade-offs:
|
||||
|
||||
* A facade can become a god object coupled to all classes of an app if not implemented correctly.
|
||||
|
||||
## Related Patterns
|
||||
## Related Java Design Patterns
|
||||
|
||||
* [Adapter](https://java-design-patterns.com/patterns/adapter/): Facade provides a unified interface while Adapter makes two existing interfaces work together.
|
||||
* [Mediator](https://java-design-patterns.com/patterns/mediator/): Facade defines a simpler interface to a subsystem while Mediator centralizes complex communications and control between objects.
|
||||
|
||||
## Credits
|
||||
## References and Credits
|
||||
|
||||
* [Design Patterns: Elements of Reusable Object-Oriented Software](https://amzn.to/3QbO7qN)
|
||||
* [Effective Java](https://amzn.to/4cGk2Jz)
|
||||
|
||||
Reference in New Issue
Block a user