开发者

How to connect the UI and business logic

开发者 https://www.devze.com 2023-02-28 22:40 出处:网络
I won\'t describe the p开发者_运维百科roject details or the framework I am using because the question is more general.

I won't describe the p开发者_运维百科roject details or the framework I am using because the question is more general.

What is the best way to create flexible interaction between the user interface and the logic. I am struggling because constantly it turns out that I have to make some feature available for the user to change via some ui but the code for the feature is somewhere deep deep in the code so I have to do lots of refactoring.

What is your approach in such situation? Maybe to model event based system where events are dispatched/handled? In my case the requirements change very often.


Use a MVx design pattern such as MVC, MVP, MVVM.

Basically:
* UI should not call BL.
* UI should raise events (or better yet, use commands).
* UI-raised-events/commands should be handled outside UI and call BL.
* BL should not call UI.
* Either modified data should raise events or BL should raise events.
* UI should know how to present data (preferably uses composition to present any type of data and not have entire UI rely on data types not changing).
* UI should refresh on events.


This really depends alot on your application. If its a webapplication the framework you are using probably have some best-practices on how to connect the UI code with buisness logic (Spring @MVC for instance).

On the other hand if you are writing a desktop application, what I usually do is use the obserever/observable pattern to have my UI code get notified of any changes to the underlying model. Again the approach to use varies with the context of the application.

0

精彩评论

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

关注公众号