Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Are there specific scenarios where Swiss Databinding is preferred over Fluent Databinding


Are there specific scenarios where Swiss Databinding is preferred over Fluent Databinding


In MvvmCross, both Swiss and Fluent databinding are used for connecting views to view models, but they serve slightly different purposes and are preferred in different scenarios.

Swiss Databinding

Swiss databinding offers a cleaner and less verbose syntax compared to its predecessor, JSON databinding. It is particularly useful when you need to define bindings in a straightforward manner, often directly in XML layout files. Swiss bindings are easy to read and write, making them suitable for simple, direct bindings where the syntax needs to be concise and understandable.

One specific scenario where Swiss databinding might be preferred is when you need to quickly set up bindings in XML files, especially in platforms where XML layouts are commonly used and easily editable, such as Android. However, Swiss databinding does not actively monitor changes from the view model unless the binding source is reset, which can be a limitation in scenarios requiring real-time updates.

Fluent Databinding

Fluent databinding, on the other hand, provides a C#-based syntax for constructing bindings. This approach is particularly beneficial in environments where XML layouts are not easily human-editable, such as iOS and macOS. Fluent bindings allow for more complex and dynamic binding setups, making them ideal for scenarios where you need to programmatically manipulate bindings or handle more intricate logic.

Fluent databinding is preferred when you need to create bindings programmatically, which can be more flexible and powerful, especially in complex applications or when working with platforms that do not support XML layouts as effectively.

Preference Scenarios

- Swiss Databinding is preferred when:
- You need a simple, easy-to-read syntax for bindings, especially in XML files.
- The application does not require continuous monitoring of changes from the view model.
- You are working in environments where XML layouts are easily editable.

- Fluent Databinding is preferred when:
- You need to create bindings programmatically, allowing for more dynamic and complex setups.
- You are working on platforms where XML layouts are not easily editable, such as iOS.
- The application requires more control over the binding logic or needs to handle complex scenarios.

In summary, while both Swiss and Fluent databinding have their strengths, the choice between them depends on the specific requirements of your application, including the need for simplicity versus complexity, and the platform you are developing for.

Citations:
[1] https://www.mvvmcross.com/documentation/fundamentals/data-binding
[2] https://crosscuttingconcerns.com/MvvmCross-Fluent-Databinding
[3] https://stackoverflow.com/questions/41462365/what-are-the-pros-and-cons-of-android-data-binding
[4] https://stackoverflow.com/questions/60500840/should-view-binding-replace-data-binding
[5] https://learn.microsoft.com/en-us/dotnet/desktop/wpf/data/?view=netdesktop-9.0
[6] https://www.phunware.com/android-clean-coding-approach/
[7] https://www.reddit.com/r/androiddev/comments/ux9379/what_are_the_use_cases_of_data_binding_and_when/
[8] https://jesseliberty.com/2022/02/01/advanced-databinding-part-0-basics/