gop
gop

Reputation: 2200

How to connect the UI and business logic

I won't describe the project 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.

Upvotes: 3

Views: 1759

Answers (2)

Danny Varod
Danny Varod

Reputation: 18069

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.

Upvotes: 5

Emil L
Emil L

Reputation: 21071

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.

Upvotes: 0

Related Questions