feat: Semaine 8
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
from typing import Protocol
|
||||
|
||||
class Notifier(Protocol):
|
||||
def send(self, message: str) -> str:
|
||||
...
|
||||
|
||||
class SlackNotifier:
|
||||
def send(self, message: str) -> str:
|
||||
return f"Sent to Slack: {message}"
|
||||
|
||||
class EmailNotifier:
|
||||
def send(self, message: str) -> str:
|
||||
return f"Sent via Email: {message}"
|
||||
|
||||
def send_alert(notifier: Notifier, message: str) -> str:
|
||||
return notifier.send(message)
|
||||
|
||||
slack_notifier = SlackNotifier()
|
||||
email_notifier = EmailNotifier()
|
||||
|
||||
print(send_alert(slack_notifier, "This is a test alert for Slack!"))
|
||||
print(send_alert(email_notifier, "This is a test alert for Email!"))
|
||||
Reference in New Issue
Block a user