Recap: Notification Channels
Lesson 42 of 48 in Coddy's Python for Dart Developers course.
Challenge
BeginnerImplement Email.send(text) returning email: plus text and Sms.send(text) returning sms: plus text. Implement Dispatcher(channels) storing a copy of the supplied list, and dispatch(text) returning one result per channel in order. Input has a space-separated line of channel names (email, sms, or log), then the message. The locked driver supplies the log channel with the same send API, creates the dispatcher, clears the original channel list, and prints dispatched results. With no channels, print none. Repeated channels produce repeated results. These methods format strings only; they never send real messages.
The locked driver handles input and output. Submit only the required class and function definitions with the exact API names. Do not read input or print from your classes.
Your code goes in the editable files email.py and sms.py and dispatcher.py. driver.py holds the supplied input/output code and API checks and cannot be edited. Keep the supplied imports; do not read input or print from the editable modules.
Try it yourself
from email import Email
from sms import Sms
from dispatcher import Dispatcher
class Log:
def send(self, text):
return "log:" + text
factories = {"email": Email, "sms": Sms, "log": Log}
channels = [factories[name]() for name in input().split()]
text = input()
dispatcher = Dispatcher(channels)
channels.clear()
results = dispatcher.dispatch(text)
if not results:
print("none")
for result in results:
print(result)
All lessons in Python for Dart Developers
1From Dart to Python
Run Your First Python ProgramInterpolation and printvar, final, and Python NamesFloor Versus TruncationBraces and Block ScopeRecap: Rewrite a Receipt4Iteration and Transformations
for-in and rangeentries and enumerateLoop Updates and continuewhere, map, and List BuildingRecap: Build a Ranking2Values and Decisions
Null Safety and NoneList Equality ChangesConditions and Null DefaultsTernaries and elifRecap: Eligibility Rules5Functions and Closures
Arrows and Explicit ReturnsNamed Calls and DefaultsExplicit Variadic ArgumentsClosures and nonlocalRecap: Refactor a Pricing Tool8Composition and Inheritance
Collaborator Objectsextends and Method ResolutionInterfaces and Duck TypingValue Classes and DataclassesRecap: Notification Channels3Collections and References
Lists and Negative IndexesRecords and Tuple UnpackingMap Lookups and KeyErrorSets and Shared ObjectsRecap: Clean an Inventory6Reliable Python Programs
stdin and Exact Formattingon, catch, finally, and withLibraries and Import ExecutionStatic Types Versus HintsRecap: Validate a Batch9Project: Order Processing
Create the Order ModelAdd Pricing PoliciesPractice on your own: Online Python compiler