cross platform development in c# (dddnorth 2013)
DESCRIPTION
Shows how to separate code to allow for maximum code reuse across iOS, Android, Windows Phone, Windows Store, WPF, and silverlight applications. Code can be found here: https://github.com/rossdargan/TalksTRANSCRIPT
![Page 1: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/1.jpg)
Cross Platform Mobile Development in C#
Ross Dargan
@rossdargan
![Page 2: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/2.jpg)
What I’m going to cover
Target 95% of the UK mobile market in C#
With maximum code re-use
![Page 3: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/3.jpg)
What I’m going to cover
![Page 4: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/4.jpg)
What I won’t cover
The other cross platform options (http://propertycross.com/)
A full walkthrough of the tooling
Blackberry
![Page 5: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/5.jpg)
Android56%
Windows12%
iOS27%
Blackberry4%
Other1%
UK Smartphone Landscape
Source: http://bit.ly/19d2thf
![Page 6: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/6.jpg)
Native DevelopmentiOS
Objective C
Xcode
Windows Phone
C#/Visual Basic/F#
Visual Studio
Android
Java
Eclipse
IntelliJ
![Page 7: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/7.jpg)
Xamarin
• C# and .NET for Android, iOS and Mac• Full native APIs
![Page 8: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/8.jpg)
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: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/9.jpg)
UI Considerations
![Page 10: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/10.jpg)
DEMOHello World
![Page 11: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/11.jpg)
So… Sharing
![Page 12: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/12.jpg)
SHARING CODEFile Linking
![Page 13: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/13.jpg)
File Linking
![Page 14: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/14.jpg)
DEMOFile Linking
![Page 15: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/15.jpg)
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: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/16.jpg)
SHARING CODEPortable Class Libraries
![Page 17: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/17.jpg)
Adding a PCL
![Page 18: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/18.jpg)
Great… but
Still need platform specific code somehow…
![Page 19: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/19.jpg)
SHARING CODEAbstract Classes
![Page 20: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/20.jpg)
Multiple Concrete Classes
![Page 21: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/21.jpg)
DEMOAbstract Classes
![Page 22: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/22.jpg)
Abstract Classes
Pros
• Quick• Easier to maintain• Follows Open/Closed
principal
Cons
• Difficult to test• Pretty inflexible
![Page 23: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/23.jpg)
SHARING CODEDependency Injection
![Page 24: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/24.jpg)
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: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/25.jpg)
DEMOPCL & DI demo
![Page 26: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/26.jpg)
Dependency Injection
Pros
• Very loosely coupled code (reuse)
• Unit tests are easy• Single Responsibility• Open/Closed
Cons
• • •
![Page 27: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/27.jpg)
![Page 28: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/28.jpg)
![Page 29: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/29.jpg)
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: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/30.jpg)
Dependency Injection
Pros
• Very loosely coupled code (reuse)
• Unit tests are easy• Single Responsibility• Open/Closed
Cons
• More code• Bloated constructors
![Page 31: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/31.jpg)
![Page 32: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/32.jpg)
Can we squeeze any more reuse out?
![Page 33: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/33.jpg)
MAXIMIZE UI CODE REUSEMVVM
![Page 34: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/34.jpg)
MVVM
Platform Specific Code
Shared Code
![Page 35: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/35.jpg)
Demo
![Page 36: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/36.jpg)
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: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/37.jpg)
3 layers of win
MVVMCross
Xamarin
Visual Studio
![Page 38: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/38.jpg)
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: Cross Platform Development in C# (DDDNorth 2013)](https://reader036.vdocuments.mx/reader036/viewer/2022062419/5584af16d8b42a125c8b5095/html5/thumbnails/39.jpg)
Questions