Conversation
Fedik
reviewed
Aug 25, 2022
| use \Joomla\CMS\Application\CMSApplicationInterface; | ||
| use Joomla\CMS\Factory; | ||
|
|
||
| class App extends Facade |
Member
There was a problem hiding this comment.
Is it a good idea to add a requirement for typehint?
/**
* @method Documeny getDocument()
* @method Potato getPotato()
* ....
* /
class App extends Facade
Member
Author
There was a problem hiding this comment.
Yes, absolutely makes sense.
Fedik
reviewed
Aug 25, 2022
| * Database | ||
| * Mail(er) | ||
| * Event | ||
| * Log(ger) |
Member
There was a problem hiding this comment.
Maybe also Layout? Currently LayoutHelper::render('blabla.layout')
And Toolbar :)
Member
Author
There was a problem hiding this comment.
The list was not ment to be exhaustive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. Summary
The facade pattern (also spelled façade) is a software-design pattern commonly used in object-oriented programming.
Analogous to a facade in architecture, a facade is an object that serves as a front-facing interface masking more
complex underlying or structural code. A facade can:
a single (and often simplified) API
loosely-coupled code
Developers often use the facade design pattern when a system is very complex or difficult to understand because the
system has many interdependent classes or because its source code is unavailable. This pattern hides the complexities of
the larger system and provides a simpler interface to the client. It typically involves a single wrapper class that
contains a set of members required by the client. These members access the system on behalf of the facade client and
hide the implementation details. [Wikipedia: Facade Pattern]
2. Why Bother?
In Joomla, we have lots of places with code like this:
or
While
Factory::getUser()is deprecated,$this->app->getIdentity()relies on knowledge about the internal structure.Being able to use
User::authorise(...);instead, would lower the cognitive load a lot. Additionally, it would make it easier for us to make changes in the
underlying code without breaking extensions that use the feature in question.
authorise()is just a single example here; there are several other places, where the facade pattern would simplify our lives: