Façade pattern implementation in PHP
Façade pattern
- basically Façade is just an object.
- User only interacts the system through our Façade object only
- It provides a unified interface to set of interfaces in sub-system
How to implement?
Example we take Login scrren.
Login screen prompts the user to enter their user name and password. AFter the user has enter the details,
LoginFaçade class is instantiated and LoginFaçade will create object for User class and will call authenticate() function in
login class. If that returns false, LoginFaçade will show the error to user, otherwise it shows the application to the user.
Our LoginFaçade class will look like this:
class LoginFacade{
public function __construct($uName,$pass){
$user = new User($uName,$pass);
$this->validateUser($user);
}
public function validateUser(User $objUser){
$login = new Login();
$flag = $login->authUser();
if($flag){
// Succees screen
;
}else{
// Erro Screen
;
}
}
// Other member function will come here
}
$objFacade = new LoginFacade(”test”,”pass”);
