Practice/Amazon/Design a Notification System
Object Oriented DesignMust
Design and implement a message delivery validation system that determines whether an incoming notification request meets all necessary criteria before it can be processed and sent to users.
Your system should implement a NotificationValidator class that checks notification requests against a set of business rules. A notification is represented as a dictionary/object containing various fields, and your validator must verify that all required fields are present and contain valid values.
The validation rules are:
NotificationValidator class with a method validate_notification that accepts a notification dictionaryTrue if the notification passes all validation rules, False otherwiseFalse rather than raising exceptions)Example 1:
Input: \{"user_id": 101, "channel": "email", "content": "Welcome!", "priority": 1\} Output: True Explanation: All required fields are present with valid values
Example 2:
Input: \{"user_id": 102, "channel": "telegram", "content": "Alert", "priority": 3\} Output: False Explanation: "telegram" is not a valid channel type
Example 3:
Input: \{"channel": "sms", "content": "Message", "priority": 2\} Output: False Explanation: Missing required field "user_id"
Example 4:
Input: \{"user_id": 103, "channel": "push", "content": "", "priority": 4\} Output: False Explanation: Content cannot be empty