开发者

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 wo开发者_开发问答uld 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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜