开发者

Is it bad form for view classes to listen and respond to their own components

开发者 https://www.devze.com 2023-03-23 19:46 出处:网络
For simpl computations, is it alright or good to have a view li开发者_开发问答sten and respond to its own components, or should a distinct controller handle ALL events, even ones like dispose() or x =

For simpl computations, is it alright or good to have a view li开发者_开发问答sten and respond to its own components, or should a distinct controller handle ALL events, even ones like dispose() or x = y?


Yes, in fact, this is quite allright. Simple computations can be handled by the view itself. e.g. You want to disable some buttons upon clicking them, then you can disable them directly from the view.

Normally, if you use the Model-View-Controller pattern, the view registers with the model, and the model updates the view each time it changes (this change occurs due to a manipulation done by the controller). However, it is allright for the view to handle simple computations. Note, however, this represents a tradeoff between efficiency and readability/flexibility- you might choose to let the controller change the model which updates the view (this is more readable and flexible, but you have to make extra function calls) or simply handle this in the view (efficient but less readable and less flexible).

If it is a simple application, I suggest you go ahead. If you intend to extend it or it is a group project which requires other programmers to extend your code, use MVC.

0

精彩评论

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