Created
November 15, 2020 13:44
-
-
Save ksmylmz/678fa33e321656f9442eab21b7f2accf to your computer and use it in GitHub Desktop.
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
<?php | |
interface IMessage | |
{ | |
public function sendMessage(); | |
} | |
////low Level sınıflarımız | |
class Email implements IMessage | |
{ | |
function sendEmail() | |
{ | |
echo "sending Email"; | |
} | |
public function sendMessage() | |
{ | |
$this->sendEmail(); | |
} | |
} | |
class SMS implements IMessage | |
{ | |
function sendSms() | |
{ | |
echo "sending SMS"; | |
} | |
function sendMessage() | |
{ | |
$this->sendSms(); | |
} | |
} | |
class PushNotification implements IMessage | |
{ | |
function sendPushNotification() | |
{ | |
echo "sending Push Notification"; | |
} | |
function sendMessage() | |
{ | |
$this->sendPushNotification(); | |
} | |
} | |
///High Level Sınıfımız | |
class MessageManager | |
{ | |
private $messageSender; | |
function __construct($messageSender) | |
{ | |
$this->messageSender = $messageSender; | |
} | |
public function sendMessage() | |
{ | |
$this->messageSender->sendMessage(); | |
} | |
} | |
/////////////// | |
///Örnek Kullanım | |
$MessageManager = new MessageManager(new Email()); | |
$MessageManager->sendMessage(); | |
////// | |
$MessageManager = new MessageManager(new SMS()); | |
$MessageManager->sendMessage(); | |
///// | |
$MessageManager = new MessageManager(new PushNotification()); | |
$MessageManager->sendMessage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment