Mobile App Multiplatform with Xamarin

Asked

Viewed 1,873 times

15

Setting

This question is more about architecture. I recently started learning Xamarin to develop Mobile Apps, Xamarin, which until then has been very flexible, has bindings for native Android and iPhone Apis.


Question(s)

  1. How the architecture of an application in Xamarin is done with a focus on code reuse between platforms?
  2. Which parts of the App should be developed for general purpose and which should be developed for a specific platform?
  3. I must keep Solutions (solutions) different for each project of each platform?

Additional Information

Any information that may be relevant to the question can be attached to the answer as well as some possible source of data on the subject.

1 answer

19


Architectures

Xamarin applications can be created basically with two major types of architecture: native and layered. I’ll explain better:

Arquiteturas Nativas

They allow you to use the same architecture that would be used if you were making the application using the platform’s native language, by default. It allows you to work exactly as you would in an Objective-C in the iOS or in Java in the Android.

The advantage of using this architecture is that it is easy to migrate to Xamarin in this way. If you already know the platform in question just do the same thing using C# instead of the native language. The downside is that you will have an application stuck on the platform and will not make use of the advantages of being able to use only one language on multiple platforms.

Architectures in Layers

They allow your application to have reusable code across platforms. Basically you can have something simple and proprietary where you separate "in hand" a reusable portion of code and all the rest that depends on the platform in different layers. There are more advanced and organized ways to do this with MVC and MVVM.

MVC - Model View Controller

It is the model that is used on the Web and that can be used with Xamarin and C# . This architecture model is made entirely by the developer with the help of libraries such as Monocross.

MVVM - Model View View-Model

It is a specialization of MVC with a layer more caring than can be abstracted and with automatic connection (binding) model with view. It’s the same architecture model that Microsoft uses on WPF - Windows Presentation Foundation. This architecture model is made entirely by the developer with the help of libraries such as Mvvmcross.


How to choose what to put on each layer

There are some libraries of Xamarin itself that abstract several native Apis. Using these libraries with a layered architecture makes you only need to rewrite the view layer for each platform.

  • Xamarin.Mobile abstract things like the camera, the contacts, the GPS
  • Xamarin.Auth allows authentication with Oauth 1.0 and 2.0
  • Xamarin.Social allows integrating Facebook, Twitter, App.net and Flickr

I must use separate solutions?

The simplest answer is no. The best is that it is a solution with only all the projects, so that the common projects can be read and loaded at once. This will facilitate your maintenance.

Remember that common libraries should not use platform-specific Apis or features and should preferably be compiled using Portable Class Libraries

Browser other questions tagged

You are not signed in. Login or sign up in order to post.