39
Cross Platform Mobile Development in C# Ross Dargan @rossdargan

Architecting cross-platform applications

Embed Size (px)

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.

Citation preview

Page 1: Architecting cross-platform applications

Cross Platform Mobile Development in C#

Ross Dargan

@rossdargan

Page 2: Architecting cross-platform applications

What I’m going to cover

Target 95% of the UK mobile market in C#

With maximum code re-use

Page 3: Architecting cross-platform applications

What I’m going to cover

Page 4: Architecting cross-platform applications

What I won’t cover

The other cross platform options (http://propertycross.com/)

A full walkthrough of the tooling

Blackberry

Page 5: Architecting cross-platform applications

Android56%

Windows12%

iOS27%

Blackberry4%

Other1%

UK Smartphone Landscape

Source: http://bit.ly/19d2thf

Page 6: Architecting cross-platform applications

Native DevelopmentiOS

Objective C

Xcode

Windows Phone

C#/Visual Basic/F#

Visual Studio

Android

Java

Eclipse

IntelliJ

Page 7: Architecting cross-platform applications

Xamarin

• C# and .NET for Android, iOS and Mac• Full native APIs

Page 8: Architecting cross-platform applications

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

Page 9: Architecting cross-platform applications

UI Considerations

Page 10: Architecting cross-platform applications

DEMOHello World

Page 11: Architecting cross-platform applications

So… Sharing

Page 12: Architecting cross-platform applications

SHARING CODEFile Linking

Page 13: Architecting cross-platform applications

File Linking

Page 14: Architecting cross-platform applications

DEMOFile Linking

Page 15: Architecting cross-platform applications

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

Page 16: Architecting cross-platform applications

SHARING CODEPortable Class Libraries

Page 17: Architecting cross-platform applications

Adding a PCL

Page 18: Architecting cross-platform applications

Great… but

Still need platform specific code somehow…

Page 19: Architecting cross-platform applications

SHARING CODEAbstract Classes

Page 20: Architecting cross-platform applications

Multiple Concrete Classes

Page 21: Architecting cross-platform applications

DEMOAbstract Classes

Page 22: Architecting cross-platform applications

Abstract Classes

Pros

• Quick• Easier to maintain• Follows Open/Closed

principal

Cons

• Difficult to test• Pretty inflexible

Page 23: Architecting cross-platform applications

SHARING CODEDependency Injection

Page 24: Architecting cross-platform applications

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

Page 25: Architecting cross-platform applications

DEMOPCL & DI demo

Page 26: Architecting cross-platform applications

Dependency Injection

Pros

• Very loosely coupled code (reuse)

• Unit tests are easy• Single Responsibility• Open/Closed

Cons

• • •

Page 27: Architecting cross-platform applications
Page 28: Architecting cross-platform applications
Page 29: Architecting cross-platform applications

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

Page 30: Architecting cross-platform applications

Dependency Injection

Pros

• Very loosely coupled code (reuse)

• Unit tests are easy• Single Responsibility• Open/Closed

Cons

• More code• Bloated constructors

Page 31: Architecting cross-platform applications
Page 32: Architecting cross-platform applications

Can we squeeze any more reuse out?

Page 33: Architecting cross-platform applications

MAXIMIZE UI CODE REUSEMVVM

Page 34: Architecting cross-platform applications

MVVM

Platform Specific Code

Shared Code

Page 35: Architecting cross-platform applications

Demo

Page 36: Architecting cross-platform applications

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

Page 37: Architecting cross-platform applications

3 layers of win

MVVMCross

Xamarin

Visual Studio

Page 38: Architecting cross-platform applications

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/

Page 39: Architecting cross-platform applications

Questions