[Answered ]-Overloading and strategy pattern

1👍

Python doesn’t have function overloading. What it does have is first-class function objects.

Create a dict that maps Receiver values to the appropriate function.

def send_to_all():
    pass

def send_to_last_three_months():
    pass

def send_to_last_six_months():
    pass

senders = {
    Receiver.ALL: send_to_all,
    Receiver.THREE_MONTHS: send_to_last_three_months,
    Receiver.SIX_MONTHS: send_to_last_six_months,
}

@api_view(["POST"])
def send_email(request):
    email_to = request.data["emailTo"]
    sender = senders[email_to]
    sender()

Leave a comment