Skip to content

Instantly share code, notes, and snippets.

@unclexo
Created May 23, 2023 15:55
Show Gist options
  • Save unclexo/95ae5decfa864e6fefbb78efa05ce325 to your computer and use it in GitHub Desktop.
Save unclexo/95ae5decfa864e6fefbb78efa05ce325 to your computer and use it in GitHub Desktop.
The Interface Segregation Principle PHP code example
<?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