CJCoding With Joseph
15free / daySign inCreate account

Polymorphic Factory From Input

A factory method can return different subclasses through the same base type, chosen at runtime. Notification is abstract with abstract string Format(string); EmailNotification and SmsNotification are complete. In NotificationFactory, finish Create(string type) so it returns an EmailNotification when type is email, and an SmsNotification otherwise. The tester reads the type and message from input. Do NOT write a Main method.

For input email then Hello the program prints the output shown in Expected Output.

For input sms then Hi it prints:
SMS: Hi

Expected Output:

Email: Hello

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Polymorphism
📥 Auto-Input:
email\nHello\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.