I have a member website, doesn't matter what language or framework as it is general question. A member can cancel his subscription from the inside and from outside. While member is inside i store his userID in session and call a function called CancelSubscription() which gets userID from session and makes a call to DB to cancel subscription. Outside uses email from newsletter on which user can click to close subscription.
Question is what is the correct, based on your bad or good experience way to create both of these func开发者_运维问答tions.
Methods:
- Create CloseSubscription with userID(integer) and with userEmail(string) as separate functions.
- Create overridden function for CloseSubscription when it gets a string as param.
- Create function in which AddUserIDFromUserEMail get's userID, saves in session and then CloseSubscription is called.
or other...
thanks
None of those solutions, because (for each of the 3):
- You'll duplicate the delete code in the 2 delete methods
- It's confusing, and one day an (unintended) implicit conversion will break it.
- CloseSubscription shouldn't rely on the presence of a session id. What if you later want to delete a subscription offline?
Thus:
4: Create CloseSubscription with userID(integer).
Create CloseSubscriptionEmail(email as string), which looks up the UserID and then calls CloseSubscription.
精彩评论