Created
May 23, 2023 15:55
-
-
Save unclexo/95ae5decfa864e6fefbb78efa05ce325 to your computer and use it in GitHub Desktop.
The Interface Segregation Principle PHP code example
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 Notifiable | |
{ | |
/** | |
* Send notifications | |
* | |
* @param array $data | |
* @return void | |
*/ | |
public function notify(array $data): void; | |
} | |
class AbcEmailClient implements Notifiable | |
{ | |
public function notify(array $data): void | |
{ | |
var_dump('Sending emails with ', $data); | |
} | |
} | |
class NotificationManager | |
{ | |
// Other methods and properties | |
/** | |
* @param array $data | |
* @param Notifiable $notifier | |
* @return void | |
*/ | |
public function notify(array $data, Notifiable $notifier): void | |
{ | |
$notifier->notify($data); | |
} | |
} | |
$abcEmail = new AbcEmailClient(); | |
$data = [ | |
'some data', | |
'more data', | |
]; | |
// Notifies users via emails | |
$emailNotification = new NotificationManager(); | |
$emailNotification->notify($data, $abcEmail); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment