EasyPython

Factory Method

PythonDesign PatternsCreational

Factory Method lets a function decide which class to instantiate based on
an input, instead of the caller hardcoding a specific class.

Implement create_notifier(kind) returning the right Notifier subclass
for 'email', 'sms' or 'push' (raise ValueError for anything else).
Each notifier's send(message) returns a tagged string.

solve(requests) takes a list of (kind, message) pairs and returns the
sent notification for each.

solve([('email', 'Welcome!')])['[EMAIL] Welcome!']

Sample tests

Test #1Single email notification
Input: [[["email","Welcome!"]]]
Output: ["[EMAIL] Welcome!"]
Test #2Mixed notifier kinds
Input: [[["sms","Your code is 1234"],["push","New message"]]]
Output: ["[SMS] Your code is 1234","[PUSH] New message"]
Test #3Empty request list
Input: [[]]
Output: []