Created
February 17, 2019 02:22
-
-
Save phptuts/953e0c0122d0670c6d3d5eb969e5a9a3 to your computer and use it in GitHub Desktop.
Strategy Design Patter
This file contains 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 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