Embracing Xamarin cross platform development is less of a process shift and more of a revolution to maximize the return on investment and time savings possible. Old regime silos between design and development must fall to conceptualize and build cross-platform experiences that translate intuitively across iOS, Android and Windows operating systems. All project members, not just the technologists, must have an intimate understanding of the capabilities and limitations of the platform. So, what makes Xamarin development unique?
Xamarin cross platform development effort optimized
With Xamarin, code works harder for your team. Experiences with 80-90% code reuse can be constructed in C# that flow across Windows, iOS and Android operating systems. The amount of code reuse possible depends greatly on the mode of Xamarin development chosen between Xamarin.Forms and Xamarin.iOS/Xamarin.Android.
Maintaining one PCL
Approximately 10% of the code reuse achieved with Xamarin comes from building and maintaining just one portable class library (PCL).
Pre-Xamarin, teams developing mobile applications for Android and iOS created and maintained different data transfer objects (DTOs) in different programming languages and would sync them with the backend system by hand. They would be created in Java for the Android app, Objective-C for iOS apps — and on.
With Xamarin.Forms and Xamarin.iOS/Xamarin.Android development, a PCL is created and defined only once in .NET serving as a single source for all DTOs on the clients. If the backend system is also .NET, then the same PCL can be used there as well.
But, is it worth it? Using an API to pull DTOs may seem like a lot of upfront work, especially for development teams who lament the days when a data field could be called directly from the server and displayed on the page.
Maintaining four sets of DTO definitions isn’t excessive — they might say. That is, unless they maintain multiple server versions running for different customers and a mistake makes it into the field. New clients must be tested against all old server versions. Suddenly the ROI of an API pulling from a singular PCL becomes apparent.
The other 70-80% of code reuse can be attributed to the MVVM development model.
Building using the Model View ViewModel with Xamarin.Forms
The user experience for apps created with Xamarin.Forms is structured using Model View ViewModel. MVVM, as it is commonly known, is a type of software architecture whereby data is bound two ways within a view, allowing the state and behavior to be abstracted for increased flexibility accommodating user interface platform changes. What this means for your project? Interface changes can be coded once in C# and applied universally.
Defining a viewmodel in Xamarin is much like its definition with Angular.JS. Unlike developing design screen-by-screen for each device. Once a change is made to a page in Xamarin.Forms, it is reflected across screens on all operating systems, alleviating teams from the burden of updating the logic for each screen.
Benefit 1: Separation. Using the Model View ViewModel approach, UI and business logic can be separated when delivering data representations across platforms.
Benefit 2: Asynchronicity. Using this architecture, your solution can run dozens of operations asynchronously (in parallel) vastly speeding data load times within your experience. The alternative is a waiting game no user wants to play.
Development approach and efficiencies are all major considerations when exploring the Xamarin.Forms value proposition.
Visualizing Xamarin.Forms development
Building using Xamarin cross platform development with Forms begins at the most fundamental level with storage. Next, comes an API to provide data access and business logic for the app. This is where your portable class library is defined and data handed back and forth from the server to the client. (The PCL, portable class library, is a common library for functionality like business rules, network, cryptopgraphy and storage that can be compiled once and used on any operating system.)
Each page in Xamarin.Forms is developed as a single screen then applied across all three platforms. These include labels, lists, buttons and layouts (that when linked with the backend) constitute a fully-native app.
Elements of Xamarin.Forms
Many teams considering Xamarin cross platform development with Forms aren’t sure they can build a “native” app with the platform. If the UI feels native, it performs like a native app (even when offline) and affords access to all device APIs — the app can be considered native. Native also means that the app is compiled to bytecode that runs directly on the processor of the device. This gives the highest performance possible on that device.
According to these definitions, Xamarin is the only cross-platform tool with the potential to create fully-native apps. The difference? Teams building with Xamarin.Forms aren’t required to invest in native-specific development talent but can create the feeling of native usability. Though, as you make app UI and behavior more platform-specific, you decrease the amount of cross-platform code and concomitant benefits.
Xamarin.Forms functions in many ways like a UI toolkit where pages and layouts that work well across all three layouts can be selected with ease.
Examples of pages: contentpage, navigationpage, tabbed page, carouselpage
Examples of layouts: stacklayout, absolutelayout, relativelayout, gridlayout
Control examples: tableview, timepicker, slider, searchbar
Though, Xamarin.Forms also allows you to customize and define your own controls. Some of the examples MentorMate has created include: Carousel control with paging and swipe gestures; circular image control which is clickable, checkable and bindable; custom date/time pickers and image buttons.
Xamarin also allows software quality teams to write UI-based test scripts. Paired with Xamarin Test Cloud, this is a powerful combination. Within Test Cloud, more than 24,000 unique Android device types and 20 iOS hardware and OS configurations exist. No device cabinet in the world is that big. Xamarin Test Cloud gives you the confidence that you are truly testing for every user scenario — efficiently. UI test scripts can be generated following your interactions, edited and uploaded to the Test Cloud for wide-scale execution.