Façade pattern implementation in PHP

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”);

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.