Skip to content

Instantly share code, notes, and snippets.

@phptuts
Created February 17, 2019 02:22
Show Gist options
  • Save phptuts/953e0c0122d0670c6d3d5eb969e5a9a3 to your computer and use it in GitHub Desktop.
Save phptuts/953e0c0122d0670c6d3d5eb969e5a9a3 to your computer and use it in GitHub Desktop.
Strategy Design Patter
<?php
interface Message {
public function send($event);
}
class Mail implements Message {
public function send($event)
{
var_dump('Sending Mail' . $event);
}
}
class Pager implements Message {
public function send($event)
{
var_dump('Page Notification' . $event);
}
}
class Notify {
public function sendMessage($event, Message $message) {
$message->send($event);
}
}
(new Notify())->sendMessage('Server Down', new Pager());
(new Notify())->sendMessage('Server Down', new Mail());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment