Skip to content

Instantly share code, notes, and snippets.

@ksmylmz
Last active May 19, 2021 06:11
Show Gist options
  • Save ksmylmz/6764f1c7e1b5eb9c6f015d201342b844 to your computer and use it in GitHub Desktop.
Save ksmylmz/6764f1c7e1b5eb9c6f015d201342b844 to your computer and use it in GitHub Desktop.
Facade Design Pattern
<?php
class BusinessLayer
{
public function UserRegister(Request $request)
{
$userManager = new UserManagerFacade();
$userManager->SaveUser($request->user);
}
}
class UserManagerFacade
{
private Validator $validator;
private UserModel $userModel;
private Logger $loggler;
function __construct()
{
$this->$validator = new Validator();
$this->$userModel = new UserModel();
$this->$loggler = new Logger();
}
public function SaveUser($user)
{
if(!$this->$validator->isUserDataValid($user)) throw new \Exception("Geçersiz Kullanıcı Bilgileri");
$this->$userModel->saveUser($user);
$this->$loggler->userProccessLogger();
}
}
class Validator
{
function isUserDataValid($user)
{
return $user?true:false;
}
}
class UserModel
{
function saveUser($user)
{
echo "User Saved";
}
}
class Logger
{
function userProccessLogger()
{
echo "User Registiration Success";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment