Design pattern for web chat client
I am developing a desktop client app for web chat. Something that is similar to icq, pidgin, skype, etc.
The client app communicates with the server through POST and GET.
Client app has these method开发者_StackOverflow中文版s:
- login
- logout
- loadFriendList
- SearchUser
- AddFriend
- SendMessage
- LoadMessages
I would like to use a design pattern for this winforms app. I am a newbie in patterns and I need advice on which design patterns are suitable for this application.
Sorry for my English. Any advice on how to organize application code with design pattern?
Thank everybody
This question is more than a little broad/vague, so I'll answer based on responding to messages.
You could go with a message pump-type pattern, similar to how Win32 operates, where you generally have a single method where you handle the messages through a switch statement. Though if it gets too big, I would put the actual logic in separate methods, and have that single method just call whatever method is appropriate.
Another pattern which is more "C#-esque" would be to use events, one for each message type. You could also add a general MessageReceived
event that would be fired for any message received, in addition to individual message types.
You could also use the state pattern. As one client will have many states. Example. An Initial (logged out) will transition to login state. While loggin you can perform operations like send message load messages etc. To get a better understanding you can search the web for state pattern
you will find many examples.
精彩评论