What is the Facade pattern in PHP/Laravel?
Answer
The Facade pattern provides a simplified, static-like interface to complex subsystems. In Laravel, facades are proxy classes that forward static method calls to underlying objects resolved from the service container. Example: Cache::get("key") appears to be a static call but actually resolves the CacheManager from the container and calls get() on it. Each facade defines a getFacadeAccessor() method returning the container binding key. Benefits: concise, readable syntax without dependency injection boilerplate for common operations. Drawbacks: can make dependencies implicit (harder to see what a class depends on) and can make unit testing harder (use Cache::shouldReceive() in tests). Real facades differ from static methods — the underlying object is injected and testable.
Previous
What is the Adapter pattern in PHP?
Next
What is the difference between method chaining and fluent interface?