โ Back to Polymorphism
Question 593
Polymorphic Factory From Input
Polymorphic Factory From Input
A factory method can return different subclasses through the same base type, chosen at runtime.Notificationis abstract withabstract string Format(string);EmailNotificationandSmsNotificationare complete. InNotificationFactory, finishCreate(string type)so it returns anEmailNotificationwhentypeisSmsNotificationotherwise. The tester reads the type and message from input. Do NOT write aMainmethod. For inputHellothe program prints: Email: Hello For inputsmsthenHiit prints: SMS: Hi
Expected Output:
Email: Hello
Topics:
Polymorphism
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.