Billy Pilgrim
Billy Pilgrim

Reputation: 1852

C# GUI & delegate use as abstraction layer

I am writing a websocket test application that will have a GUI to send various commands over the websocket. Rather than pack all the control code (message construction, formatting, control) into the callbacks for various controls, I am considering having each GUI element callback (e.g., onClick) send an event to a delegate that can handle it. That way the GUI would be separate from any control code. Is that a 'sane' design, or is there another 'best practice' to separate the two parts.

An example would be a TV Tuner control -- the user can enter a channel number via textbox, which will have no effect until they click the 'Tune' button. The onClick method could retrieve the channel number from the textbox, and send a doTune(channel) event to the delegate to make it happen.

Thoughts/advice welcome.

Thank you, bp

Upvotes: 5

Views: 334

Answers (2)

HTBR
HTBR

Reputation: 1023

This is indeed a sane design. I personally won't go for an event call, just a regular call to a static 'SocketCommands' class will do.

Upvotes: 1

MattDavey
MattDavey

Reputation: 9027

That is indeed a very sensible design - what you're doing is promoting a good seperation of concerns between the presentation layer (UI) and the business layer (transaction scripts, domain services etc).

So to answer your question, yes, it is a sane design :)

With regards to thoughts/advice, that would be a topic for programmers.stackexchange.com rather than here..

Upvotes: 1

Related Questions