Skip to content

Instantly share code, notes, and snippets.

@ksmylmz
Created November 15, 2020 13:44
Show Gist options
  • Save ksmylmz/678fa33e321656f9442eab21b7f2accf to your computer and use it in GitHub Desktop.
Save ksmylmz/678fa33e321656f9442eab21b7f2accf to your computer and use it in GitHub Desktop.
<?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