Top 5 interview questions for Xamarin Forms

For the past 5 years that I’ve been working with Xamarin Forms, I’ve been part of a bunch of interview processes, so I have gathered the top 5 questions a Xamarin engineer could ask you in an interview ( or at least the questions that have asked me the most times ). They are listed from most important to “less important”

1.- How does Xamarin works?
This one I get a lot so make sure you understand it 🙂

Although Xamarin allows you to write apps in C#, and share the same code across multiple platforms, the actual implementation on each system is very different.

Compilation:

iOS – C# is ahead-of-time (AOT) compiled to ARM assembly language. The .NET framework is included, with unused classes being stripped out during linking to reduce the application size. Apple does not allow runtime code generation on iOS, so some language features are not available (Limitations ).
So… Xamarin’s Ahead-of-Time ( AOT) Compiler compiles Xamarin.iOS applications directly to native ARM assembly code.


Android – C# is compiled to IL and packaged with MonoVM + JIT’ing. Unused classes in the framework are stripped out during linking. The application runs side-by-side with Java/ART (Android runtime) and interacts with the native types via JNI (Limitations ).
So… Android, Xamarin’s compiler compiles down to Intermediate Language ( IL), which is then Just-in-Time ( JIT) compiled to native assembly when the application launches.

As a side note:
In both cases, Xamarin applications utilize a runtime that automatically handles things such as memory allocation, garbage collection, underlying platform interop, etc.

2.- Define MVVM pattern

Model, View, ViewModel – The Model-View-ViewModel pattern is popular with frameworks that support data-binding, such as Xamarin.Forms. It was popularized by XAML-enabled SDKs like Windows Presentation Foundation (WPF) and Silverlight; where the ViewModel acts as a go-between between the data (Model) and user interface (View) via data binding and commands.

3.- What are the differences between a .NET standard project and a Shared project?

.NET Standard projects can implement code to be shared across multiple platforms and can access a large number of .NET APIs (depending on the version). .NET Standard 1.0 – 1.6 implement progressively larger sets of APIs, while .NET Standard 2.0 provides the best coverage of the .NET BCL (including the .NET APIs available in Xamarin apps).

Benefits:

  • Allows you to share code across multiple projects.
  • Refactoring operations always update all affected references.
  • A larger surface area of the .NET Base Class Library (BCL) is available than PCL profiles (Deprecated). In particular, .NET Standard 2.0 has almost the same API surface as the .NET Framework and is recommended for new apps and porting existing PCLs.

Shared Projects contain code files and assets that are included in any project that references them. Share projects do not produce compiled output on their own.

For example, a cross-platform application that supports iOS, Android, and Windows would require an application project for each platform. The common code lives in the Shared Project.

Benefits:

  • Allows you to share code across multiple projects.
  • Shared code can be branched based on the platform using compiler directives (eg. using __#if ANDROID__ ).
  • Application projects can include platform-specific references that the shared code can utilize.

The main disadvantages of a Shared project are:

  • Refactorings that affect code inside ‘inactive’ compiler directives will not update the code inside those directives.
  • Unlike most other project types, a Shared Project has no ‘output’ assembly. During compilation, the files are treated as part of the referencing project and compiled into that assembly. If you wish to share your code as an assembly then .NET Standard is solution for you.

4.- What is the Dependency Service?

The DependencyService class is a service locator that enables Xamarin.Forms applications to invoke native platform functionality from shared code.

Note: This is not really an IoC container. (Here is a great answer of what is the difference between Dependency Injection and Service locator)

The process for using the DependencyService to invoke native platform functionality is to:

1.- Create an interface for the native platform functionality, in shared code.
2.- Implement the interface in the required platform projects (iOS / Android…).
3.- Register the platform implementations with the DependencyService. This enables Xamarin.Forms to locate the platform implementations at runtime.
4.- Resolve the platform implementations from shared code, and invoke them.

5.- How do you style your views for different resolutions
This is the most time consuming one. But you can answer with different points like:

  • Fonts: There is an enum that can help you render the fonts correctly on different device resolutions. (Detail Info)
  • Consider using the correct layout for your page. (Usually, FlexLayout helps)
  • OnSizeAllocated method of a Page helps you to recognize the device orientation. (Detail Info)
  • Use font awesome instead of images for your icons. (Detail Info)
  • @Chard003 Created a great post about this that can actually help you answer this question 🙂 (Detail Info)

What do you think about this interview questions? Leave your comments on the section below and tell me which questions have you got an interview so we can create a cheat sheet to easily land the job a Xamarin.Forms job!

It is always a pleasure to write for you! Don’t forget to subscribe and share this post on the social network of your preference 😀

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s