Forum General

Xamarin Native UWP Design Pattern and Architecture

XamarinMobileDevXamarinMobileDev FRUniversity

I'm doing a Xamarin Native Project, my goal is to have the three platforms : iOS, Android and UWP.

So I have 4 Projects :

  • PCL
  • Xamarin.iOS
  • Xamarin.Android
  • UWP

For Xamarin iOS and Xamarin Android I wan't to use the MVC pattern because it's the most used in these plateformes. But The UWP platform use the MVVM pattern as reference.
The major problem is to manage the navigation.
How can I do to combine theses two patterns or may be I'm in the wrong way ?

Posts

  • RyanDixonRyanDixon USMember ✭✭✭
    edited June 2017

    TL;DR: In MVC all actions have to go through a controller or service layer. In MVVM the view model can directly modify the view.

    You're going about it the wrong way :smile:
    MVC (Model-View-Controller) -> Essentially, an action on the view goes through the controller or service layer to manipulate the model, which in term changes the view again.

    MVVM (Model - View - ViewModel) -> An action on the view manipulates the ViewModel, which in term manipulates the model and the view.

    Essentially MVVM is complete event driven by nature, whereas MVC normally requires some form of developer/user action to take the changes from the model to the view. Whether this is a page refresh, or an ajax request. This is why its the go to solution for systems like Spring MVC (go figure).

    In MVVM, the VM (View Model) acts as both the service and the controller; when you modify it, it will automatically propagate for you, with very little work needed. Its a lot less boilerplate than the former.

    Check out MVVMLight as a simple example, it should make things clear for you just by playing about with it for five minutes with Xamarin Bindings.

  • XamarinMobileDevXamarinMobileDev FRUniversity

    OK thanks for your answer :smiley:

    To clarify technically, if you have a service, a model and a ViewModel it's perfect for using MVVM pattern but in the case of iOS you have the controller extra, for me in this case it's a mix of MVVM and MVC, because I have a View Model and a Controller that are doing pretty the same things.
    The best way is not to have common service and model to the three platforms and use the view model for the UWP platform to respect the MVVM pattern and use the controller without the ViewModel in the iOS project to respect the MVC pattern ?

Sign In or Register to comment.