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.
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 theClient
class sounds ok to me though.