1

I am writing a client server application. I wanted to fully separate the server logic, from the view. The first thing I wanted to to, is to make a sort of a message log.

The server itself should not know if the messages will be shown at a GUI, or on the console.

What I was thinking, would be to have a handler method, that would be called every time a new message was posted. So a GUI app would have it's own method to maybe add to a listView, while the console would have a simple printf.

Is there a better way to do this?

asked Jan 2, 2014 at 12:01

1 Answer 1

0

You're on the right track and more or less describing the Adapter Design Pattern, which is defined by wikipedia as:

Adapter design pattern is used when you want two different classes with incompatible interfaces to work together. Interfaces may be incompatible but the inner functionality should suit the need. The Adapter pattern allows otherwise incompatible classes to work together by converting the interface of one class into an interface expected by the clients.

In your case, you would probably have a GUI adapter and a Console adapter, both which would consume handle the server messages as appropriate for their user interface and you would instantiate at run-time whichever adapter is most appropriate.

answered Jan 2, 2014 at 15:13
2
  • what about making a ServerClass with an empty onReceiveMessage function that will be overriden by a ServerGUI and SererConsole subclasses? Commented Jan 2, 2014 at 15:54
  • 1
    That doesn't sound like its decoupled like you want it and also seems to be suggestive of doing on the server side, not the client side. What you should be thinking about is the server's API independently of how its results are digested by the clients. Then you write the clients to consume that API. These days, I write servers that consume JSON and reply with JSON, so if you're thinking in these restrictive terms, you'll probably more readily see the natural decoupling points for your client/server. Commented Jan 2, 2014 at 16:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.