Does Facade in Laravel implements Facade or Proxy Pattern?
Asked Answered
E

1

11

As I understood, the Facade Pattern's intent is

to 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. This can be used to simplify a number of complicated object interactions into a single interface.

enter image description here

From what i understood is, the pattern's goal is to hide complexity in subsystem (e.g. You facade class calls many objects in subsystem).

But in Laravel's Facade it only has one class calls another class (not a subsystem). To me it looks more like a Proxy more than Facade. Can some one helps clarify this to me.

Erl answered 26/6, 2013 at 23:50 Comment(0)
S
2

The book, Architect's Guide to PHP Design Patterns notes,

The purpose of the Facade is to present a simpler interface to an entire sub-system composed of many objects.

At my understanding, design patterns are not a "priori" obligation but rather a commitment to implement a general reusable solution to a commonly occurring problem.

Laravel 4 takes advantage of the Facade Design Pattern, which allows it to provide an expressive syntax through a static API but still keep it testable under the hood. The Facade hides the complexity / implementation of the code. Indeed, Laravel's Facades implement a single object. We shouldn't neglect though that Laravel's App Facade (an IoC container) encapsulates the whole application .

A Proxy pattern intercepts a request and does extra work, for instance: filtering, ACL, transformation... The "consumer" Object is blissfully unaware of that extra work provided by the Proxy layer.

Seema answered 25/10, 2013 at 8:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.