Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

MVU, ReactiveUI and MVVM in .Net Maui

The maui team is integrating MVVM,ReactiveUI and MVU in the framework. I know that ReactiveUI is also a MVVM framework. But still it is different than the Xamarin.Forms MVVM. Does ReactiveExtensios can be useful with MVU architecture.
What are the pros and cons of using each one of them?
I expect someone with knowledge of app architectures to throw light on the matter. This will help existing as well as new developers in choosing the right architecture before they start coding.

Posts

  • ParamjitSinghParamjitSingh USMember ✭✭
    edited October 18

    MVVM(Model View ViewModel)
    MVVM is the default built in architecture design pattern in the xamarin.Forms framework. The UI in MVVM is Mutable. Which make managing the state difficult and cause many issues. It consists of three parts.
    • Model- The definition of data
    • View- The User Interface for user to interact with the app
    • ViewModel- The ViewModel stays in between the View and Model. It have all the business logic and presentation logic.
    The MVVM enable to keep the UI code, Logic and Data separate. Thus it help in easy maintenance.
    You can learn more about MVVM at https://docs.microsoft.com/en-us/xamarin/xamarin-forms/enterprise-application-patterns/mvvm

    ReactiveUI
    ReactiveUI is a framework which enables use of Reactive Programming over MVVM design pattern. Reactive Programming is done using Reactive Extensions. The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. ReactiveUI make mutable state managable. DynamicData is part of ReactiveUI which makes managing any kind of data very efficient. The definition given at reactiveui.net is “An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms!”. The Reactive code is concise and testable. You can learn about it at https://www.reactiveui.net/

    MVU( Model View Update)
    MVU is a Functional Reactive Programming, architecture design pattern. In MVU UI is immutable. So you have to rebuild your UI, every time you wanted to update a property. Immutability is the property of Funtional Programming. C# does support Functional programming paradigm. C# is taking it further with C# 9 and dot net 5 release in November 2020.
    In this setup the UI and business login is written in same language e.g C#. The flow of data is unidirectional. It is Good fit for hot reload of the application. You don’t need to learn XAML for developing UI instead develop complete application in one language. The maui implementation of MVU is here https://github.com/Clancey/Comet

    Conclusion
    So, this is not about one versus the other. This is about choosing the right tool for the job. Mutability have significance in some scenarios. For UI heavy Mobile apps the MVU architecture is the best. For me all these architectures are like a steps of the ladder. First I used MVVM because as a UWP(Universal Windows Platform) developer I already knows XAML and MVVM. Then I started learning ReactiveUI and with experience I learn the obvious benefits of using it. Now MVU will be supported by maui. MVU is an excellent solution for cross platform mobile apps. Xamarin.Forms team is moving in the right direction.

  • JohnHardmanJohnHardman GBUniversity admin
    edited October 18

    @ParamjitSingh

    Immediate thoughts rather than a complete response:

    @ParamjitSingh said:
    • ViewModel- The ViewModel stays in between the View and ViewModel.

    Should read "View and Model"

    @ParamjitSingh said:
    • Model- The definition of data
    ...
    • ViewModel- The ViewModel stays in between the View and ViewModel. It have all the business logic and presentation logic.

    Different people interpret MVVM in different ways, but even the document that you linked to says of the Model, "the model can be thought of as representing the app's domain model, which usually includes a data model along with business and validation logic" (my addition of bold).

    @ParamjitSingh said:
    MVU( Model View Update)
    ...
    In this setup the UI and business login is written in same language e.g C#.

    MVVM does not require people to use XAML. It too can be implemented purely in C#, whether or not using the C# Markup extensions. So using just C#, rather than a combination of C# and XAML, is not a benefit of MVU over MVVM.

    @ParamjitSingh said:
    The maui implementation of MVU is here https://github.com/Clancey/Comet

    As the Comet documentation says, "Comet is a proof of concept. There is no official support. Use at your own Risk".

    Comet is not "the" MAUI implementation, it is "a" MAUI implementation.

    Note that David Ortinau has said of MVU in MAUI, "we have a prototype. Yes, it's inspired by the Comet experiment" (ref. https://github.com/dotnet/maui/issues/118#issuecomment-635052337 ).

    @ParamjitSingh said:
    For UI heavy Mobile apps the MVU architecture is the best

    What are the criteria for "best"?

  • ParamjitSinghParamjitSingh USMember ✭✭

    @JohnHardman said:
    Should read "View and Model"

    My bad, corrected the mistake

    @JohnHardman said:
    Different people interpret MVVM in different ways, but even the document that you linked to says of the Model, "the model can be thought of as representing the app's domain model, which usually includes a data model along with business and validation logic" (my addition of bold).

    Yes, different people interpret MVVM in different ways. What I wrote is what I see in practice. In almost every Xamarin.Forms codebase I reviewed have all the business and presentation login in ViewModel.

    @JohnHardman said:
    MVVM does not require people to use XAML. It too can be implemented purely in C#, whether or not using the C# Markup extensions. So using just C#, rather than a combination of C# and XAML, is not a benefit of MVU over MVVM.

    Again it is a general practice to write UI in XAML in the Xamarin Community. Using C# is just one of the benefits of using MVU over MVVM. The biggest benefit is immutability

    @JohnHardman said:
    As the Comet documentation says, "Comet is a proof of concept. There is no official support. Use at your own Risk".
    Comet is not "the" MAUI implementation, it is "a" MAUI implementation.

    This is little bit confusing. @JamesClancey is Microsoft Employee. So what he is building is MVU framework for dotnet maui. It may not be supported yet. But it will be supported. It is underdevelopment so the project will certainly change by the time it is released.

    @JohnHardman said:
    What are the criteria for "best"?

    When I said best I mean using it will result in less bugs and easy maintenance of the app in comparison to MVVM and ReactiveUI. Further the apps will be more performant due to lack of XAML and Bindings.

  • JohnHardmanJohnHardman GBUniversity admin
    edited October 18

    @ParamjitSingh said:
    Again it is a general practice to write UI in XAML in the Xamarin Community. Using C# is just one of the benefits of using MVU over MVVM.

    Given the support for C# Markup, I believe the number of people using C# to develop MVVM is increasing. The previously accepted argument for using XAML (that designers could build UIs in XAML but couldn't in C#) seems to now be accepted as misleading, as there seem to be very few designers developing XAML. IMHO, that might change if MS Blend could be used to build Xamarin.Forms and/or MAUI UIs, but that doesn't look likely to happen. (Note that I have no metrics to support this paragraph - perhaps @DavidOrtinau or @VincentH have?)

    @ParamjitSingh said:
    The biggest benefit is immutability

    Agreed, particularly for those not familiar with state tables and state transitions.

    @ParamjitSingh said:
    When I said best I mean using it will result in less bugs and easy maintenance of the app in comparison to MVVM and ReactiveUI. Further the apps will be more performant due to lack of XAML and Bindings.

    It will be interesting to see how performance compares in real-world scenarios. Experience has shown that assumptions about performance are often unreliable, even for those with long experience of performance-related work (other than cases where there's an obvious difference in algorithm etc). It normally takes measurement to be certain.

  • ParamjitSinghParamjitSingh USMember ✭✭

    @JohnHardman said:
    It will be interesting to see how performance compares in real-world, like-for-like (so C# vs. C#, not C# vs. XAML) scenarios. Experience has shown that assumptions about performance are often unreliable, even for those with long experience of performance-related work (other than cases where there's an obvious difference in algorithm etc). It normally takes measurement to be certain.

    We have to wait till maui release(November, 2021) to do comparative analysis of all these UI paradigms. But certainly maui developers will have lots of options for developing cross platform apps. With experience one can learn to use right tool for the job.

Sign In or Register to comment.