I have been working on a mobile application for one week, for personal education and enhancement. I have some experience with WPF and MVVM, I have no experience with mobile development.

The idea is to make a cross platform application, while testing some coding philosophies :

I plan to use the following components :

  • Prism.Unity.Forms : seems to provide application structure, ioc, navigation, seems widely used, and done by top notch people
  • ReactiveUI, ReactiveUI.XamForms, ReactiveUI.Fody : WhenAnyValue, ObservableAsPropertyAttribute, ReactiveAttribute (tutorial), not using them looks like a huge missed opportunity to me

The current structure of my Visual Studio is the following :

  • Csproj
    • ViewModels
      • CreateExercisePageViewModel
      • HomePageViewModel
    • Views
      • CreateExercisePage
      • HomePage

I managed the following :

  • Set the HomePage as the initial Page, contained inside a NavigationPage, by using the navigation functionalities of Prism.
  • Declare a named button in XAML, set its Command property through a OneWay binding created in code behind, using ReactiveUI functionalities (like shown in the tutorial, using the WhenActivated method)
  • Navigate to the second page (CreateExercisePage), using Prism navigation

One issue is that, even though I have seen a few articles regarding vertical slicing, there were mostly about web applications.

So the question is : Is vertical slicing applicable to mobile applications ?

I would like to restructure my project by using vertical slicing, but having troubles finding articles about Xamarin Forms, I feel uneasy.

Edit : my understanding of the vertical slicing concept, is that you should group code, related to a feature, in the same physical space (folder). By doing so, it gives developers a huge hint about the cohesion of those files.

Given a mobile application is made of screens, I assumed grouping code by screen, regardless of their type (presentation, logic, persistence) would make sense.

Rewriting the application would give the following csproj, then :

  • Csproj
    • Screens
      • Home
        • HomePage
        • HomePageViewModel
      • CreateExercise
        • CreateExercisePage
        • CreateExercisePageViewModel

Adding a new screen would mean adding a new folder to the "Screens" folder, reducing the risk of modifying existing files/logic.

1 Answers

0
Land Lu - MSFT On

Vertical Slicing is a little bit like MVVM which we are utilizing on Xamarin.Forms: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/enterprise-application-patterns/mvvm The view is the UI layer, view model helps you handle the logic code and model represents your database data.

For instance, a user clicks the button on view layer to trigger a command in the view model. Then this command could add a new product to the List property of that view model. As this list property has been changed it will notify the UI to respond to this action.

Moreover, your first architecture is more appropriate:

  • ViewModels
    • CreateExercisePageViewModel
    • HomePageViewModel
  • Views
    • CreateExercisePage
    • HomePage

Make your pages separated by your view models.