mardi 26 août 2014

Laravel facades...misuse the term, they are proxies, ok?

The problem with the advent of Laravel and its popularity, is that it teaches wrong ideas to a huge amount of people.

Laravel facades are not facades. They definetely misuse the term.
What Laravel calls facade is just an opaque PHP magic method wrapper.
Said differently they're static proxies to service locators.

A proxy should be called a proxy, it is a pattern used elsewhere like in Java (RMI), Corba, etc.
You should also read about "dynamic proxy".

How are they different?
A facade hides something that takes a complex, multi-step operation, and simplifies it. So the interface (=public methods) is different: it is simplified, and 1 method call replaces several calls to one or many objects.

A proxy on the other hand has the exact same interface (meaning same list of public methods) of 1 proxied object, and usually add a feature (in example like logging method calls or usage of a network call).
(for some it could be confused with Decorator).

Learning programming "design patterns" is quite difficult, and this kind of framework is a danger from ths perspective.
So please take 2 minutes to learn the real facade design pattern: design_patterns/facade or here proxy-pattern.

I am glad some people know design patterns (@pmjones):  I could not resist to add my word to this discussion: about laravel facade.
Finally as I said there, maybe it is PHP magic methods are just plain evil for OO design.



Related Posts:

  • PHP 5.3.29 came out, and it is EOL - End of Life 14 Aug 2014: The PHP development team announces the release of PHP 5.3.29. This release marks the end of life of the PHP 5.3 series.  The thing is: why putting it EOL now, when it is the most widely used vers… Read More
  • acronym of the day: YAGNI This is an important principle, as important as it is easy to understand. It stands for "You aren't gonna need it". Quoting Wikipedia (YAGNI at wikipedia): You aren't gonna need it" is a principle of extreme programming (… Read More
  • Laravel facades...misuse the term, they are proxies, ok? The problem with the advent of Laravel and its popularity, is that it teaches wrong ideas to a huge amount of people. Laravel facades are not facades. They definetely misuse the term. What Laravel calls facade is just … Read More
  • The Web is Us Welcome to my discussion on current web trends. I am sharing here my expertise and interests about web technologies - and my toughts about it. A tought I had the other day: The Web is us - The Techies If you always ask "w… Read More
  • Is it me, or Laravel Lumen is actually pure sham? When I heard about that new Lumen framework, I said "Great, they decided to do something about the poor performance of Laravel". Lumen advertize itself (frontpage) as "The stunningly fast micro-framework by Laravel." or "a … Read More

2 commentaires:

  1. And what of cases where Laravel Facades ARE Facades (there are a few where they are not straight up proxies?).


    In Laravel, Facade is used as a noun, not an adjective. It's a "trade name" if you like, and it leans on the pre-existing english definition of the word, not the GoF pattern definition of the word.

    Can we please stop flogging this dead horse now?

    RépondreSupprimer
  2. I can't see any real Facades in the Laravel code.
    Anyway I understand people are free to name their stuff the way they want.
    At least there must exist traces online to debunk the misuse for those willing to go deeper, who search & learn.

    RépondreSupprimer