architecting cross-platform applications
DESCRIPTION
The mobile device offers great potential for enhancing customer service, reducing risk or improving productivity. To be effective, however, any application or mobile interface must accommodate the wide range of differing manufacturers and diverse operating systems. Mobile Development Specialist, Ross Dargan covers how to write a cross platform application using c#. He demonstrates how easily you can target iOS, Android and Windows phone 8 using tools you will already be familiar with as a c# developer. Ross explains how to use good coding techniques to ensure a high amount of code reuse for both the back end core logic, and the front end user interface.TRANSCRIPT
Cross Platform Mobile Development in C#
Ross Dargan
@rossdargan
What I’m going to cover
Target 95% of the UK mobile market in C#
With maximum code re-use
What I’m going to cover
What I won’t cover
The other cross platform options (http://propertycross.com/)
A full walkthrough of the tooling
Blackberry
Android56%
Windows12%
iOS27%
Blackberry4%
Other1%
UK Smartphone Landscape
Source: http://bit.ly/19d2thf
Native DevelopmentiOS
Objective C
Xcode
Windows Phone
C#/Visual Basic/F#
Visual Studio
Android
Java
Eclipse
IntelliJ
Xamarin
• C# and .NET for Android, iOS and Mac• Full native APIs
The bad…
• Price $2000 per dev per year• Still need a mac• Write once, run (and test!) everywhere• Tooling is still a bit immature (but the
support is great!)• Need to write each UI separately
UI Considerations
DEMOHello World
So… Sharing
SHARING CODEFile Linking
File Linking
DEMOFile Linking
File Linking
Pros
• Quick
Cons
• Messy code• Progressively more
difficult to maintain as you add implementations
• Very hard to test• File linking is a PITA to
remember as you add files
SHARING CODEPortable Class Libraries
Adding a PCL
Great… but
Still need platform specific code somehow…
SHARING CODEAbstract Classes
Multiple Concrete Classes
DEMOAbstract Classes
Abstract Classes
Pros
• Quick• Easier to maintain• Follows Open/Closed
principal
Cons
• Difficult to test• Pretty inflexible
SHARING CODEDependency Injection
Dependency Injection
• Helps separate code (Single responsibility)• Allows you to unit test’s discrete parts of
the implementation – no God classes• You can inject in platform specific
implementations• Inversion of Control allows you to swap
implementations easily
DEMOPCL & DI demo
Dependency Injection
Pros
• Very loosely coupled code (reuse)
• Unit tests are easy• Single Responsibility• Open/Closed
Cons
• • •
What are the downsides to using Dependency Injection?
It can be dangerous for your career because it may increase your overall knowledge of good API design. Once you learn how proper loosely coupled code can look like, it may turn out that you will have to decline lots of job offers because you would otherwise have to work with tightly coupled legacy apps. Happens to me a lot :)
Source: http://bit.ly/com6aD
Dependency Injection
Pros
• Very loosely coupled code (reuse)
• Unit tests are easy• Single Responsibility• Open/Closed
Cons
• More code• Bloated constructors
Can we squeeze any more reuse out?
MAXIMIZE UI CODE REUSEMVVM
MVVM
Platform Specific Code
Shared Code
Demo
Improving Code Reuse in 3 easy ways
• Heavy use of dependency injection– Allows different implementations for different
platforms
• Use PCLs (and file linking for the time being)
• Use View Models to reuse presentation code
3 layers of win
MVVMCross
Xamarin
Visual Studio
Links
• http://xamarin.com/• http://mvvmcross.wordpress.com/• http://propertycross.com/• https://github.com/rossdargan/Talks• Dependency Injection in .Net by Mark
Seemann (ISBN: 1-935182-50-1)• http://www.icndb.com/api/
Questions