Notification System with Polymorphism

Create a class Notification with a method notify(). Extend this class into EmailNotification and SmsNotification, each implementing the notify() method appropriately.

Example 1:

Input: EmailNotification 
Output: "Sending email notification"

Example 2:

Input: SmsNotification
Output: "Sending SMS notification"

Override the notify() method in each subclass to return the respective notification method.

class Notification:
    def notify(self):

class EmailNotification(Notification):
    def notify(self):
        return "Sending email notification"

class SmsNotification(Notification):
    def notify(self):
        return "Sending SMS notification"

# Test the classes
email_notification = EmailNotification()
print(email_notification.notify())  # Output: Sending email notification

sms_notification = SmsNotification()
print(sms_notification.notify())  # Output: Sending SMS notification

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!