Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 819
Billy Pilgrim Avatar asked Nov 05 '22 14:11

Billy Pilgrim


2 Answers

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.

like image 56
HTBR Avatar answered Nov 12 '22 20:11

HTBR


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..

like image 31
MattDavey Avatar answered Nov 12 '22 22:11

MattDavey