3

I am having chalice project and using that i am sending mails to the clients. Every client is associated with an organization. Till now i was using same template for all clients but now i need to make changes in the mail template at organization level like every organization demand different things in the mail for their users. Should i use factory design pattern in chalice for solving this problem if organizations are more than 50. I doubtful because for that i have write 50 different classes for each organization Or should I use decorator feature of python which can wrap every function as per the requirement. Please help me with this if you are having clear knowledge of Design pattern.

def userDecoratorMail(func): #passing method as first class function
    def wrapperFunc(appdata):
        if appdata["org_id"] == 5: #checking the condition with client id
            return func(appdata)
        return "Secondary Template"  #return secondary templte.
    return wrapperFunc
        
@userDecoratorMail     
def mail(appdata): # Base method
    return appdata #some mail function will get trigger with appdata information
dict1 = {"user_id":"123","username":"chandresh","org_id":5}

mail(dict1) # calling base method.

Problem statement (using Chalice) :- i have 10-20 methods which are sending mail on different events for users. every user is associated with a orgnization( Client). Client are more than 50 and now every client want different mail content for their users like customized kind of thing. In this case should i use decorator or Factory design pattern. I have written sample decorator code for that.

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 25 '21 at 12:19
  • Hi have problem statement below for more clearly explaining. – Chandresh Chahar Oct 25 '21 at 14:15
  • Both solutions can be used but factory design pattern would be more modular as far as code modularity is concerned – vtustudent Oct 26 '21 at 13:51

0 Answers0