c# - What design pattern fits the bill in this scenario? -
I am writing an application to get an SMS message via an HTTP gateway. Main processing I will be processing the sender's phone number and message only, depending on the keyword in the message, I will need to perform different logic / return a different reaction, to start with, I have used a simple experiment / If a switch turned into statement, and now I'm trying to clean it a little bit.
I think what kind of implementation of some kind of command is the pattern, but I'm not sure. I can implement every operation as a command object and I can register them all with the command processor, but then I have to implement the appropriate command to execute the ConvexAuute (...) function . For situations where a command should be executed, they may depend on many factors such as keywords or specific message content.
I'm thinking something like the following:
Public interface ISSS Commands {Bull Canaxet (string sender, string message); String executed (string sender, string message); } Public Class SMS Help Comand: ISSSC Command {Public Bull Canaxute (String Sender, String Message) {Return (Message., Tuller). Start ("Help")); } Public string Execute (string sender, string message) {return "For more information, go to ..."; }} Public class SMSHP handler: IHttpHandler {list & lt; ISSS Commands & gt; _commands = new list & lt; ISSS Commands & gt; (); Public Bull IRUUL Eligible {Returns Correct; }} Public Zero Process Request (HttpContext Reference) {var Sender = context.Request.Form [...]; Var message = context.Request.Form ["message"]; Forex Currency (var command in _commands) {if (command.CanExecute (Sender, Message)) {var response = command.Execute (Sender, Message); SendTextMessage (sender, feedback); break; }}}}
Something about this code seems to mess me up, though. I do not like to send logic in both the canxquette function and the execute function, but I'm not sure. Any ideas?
I will continue with the command pattern, but remember that patterns are just guidelines (although I imagine Do not go without saying that).
Although usually in the command pattern, you supply it with something so that it can be run on the command. Think about how the SqlCommand object works, you give it SqlConnection and ask it to execute only. Command object that is required, uses SqlConnection. You put your pad on the gas pedal and this car transfers all the links to move fast. You do not push the gas pedal and then open the throttle yourself.
What would I suggest that you can either give commands to the SendTextMessage
function or object that allows for that functionality (think of SqlConnection) in its creator or Do this only with the sender
and message
with the execute
method. It gives you the ability to allow the command to work. While at the same time allow you to disrupt your ability to do this through the SendTextMessage
functionality, it can do it if it can and if it can not, because it No messenger, this message will not send.
Comments
Post a Comment