4

I want to improve my multi-threading and design pattern skills. As such I'm designing an Instant Messaging server.

I'm writing the Server first.

My plan so far is to have Client "Proxy" Classes to handle the socket connection for each Client. I want to have an "Exchange" Class that takes a message from a Client Proxy and hands it to the recipient Client Proxy.

I was thinking of having both the Client and Exchange observe each other in this situation via the Observer Pattern. Mutual observers as it were, with Client Proxy and Exchange being Observer and Subject.

On further thinking, should I instead have just the Exchange be the Observer and the Client Proxies as multiple Subjects for the Exchange?

-- Further thoughts

It seems people quite like the idea of mutual observation between Proxy and Exchange. I was planning on each Client Proxy running in a separate thread. Would the Exchange become the bottleneck if there's only one Object?

It sounds to me like I might need a pool of exchange objects, but I'm unsure how that would then map to the Observer pattern, even if I had some kind of broker in front of my pool of workers.

migrated from stackoverflow.com Sep 23 '13 at 17:44

This question came from our site for professional and enthusiast programmers.

  • Sounds pretty good.. – codeMan Sep 11 '13 at 13:59
  • Thanks codeMan, can you take a look at my second approach? – retrodev Sep 11 '13 at 14:00
  • It's to hand a message to another Client Proxy. I thought of having Client Proxies observer their online "Buddies", but I'd still need to inform those Classes when other Clients come online. – retrodev Sep 11 '13 at 15:11
  • After reading the question a couple of times, and having no idea on how real applications of this kind are actually implemented, I'd suggest you to ditch the Exchange class, conceptually I find it too abstract. There could be a central "hub" system delivering stuff to clients but to abstract each communication act in a class sounds a bit odd to me. The Observer and Proxy patterns applied to the Client class sounds ok to me though. – Mister Smith Sep 11 '13 at 15:49
  • It seems more like the Mediator Pattern to me. The mediator will handle the complexity of sending multiple messages to multiple objects. – Henrique Barcelos Sep 12 '13 at 12:57
0

I think viewing both the Exchange and the Client Proxy as observers makes sense. Logically, events can happen both places so it makes sense to have each one "watching" the other for an event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.