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
Blackber...
Android
56%
Windows
12%
iOS
27%
Blackberry
4%
Other
1%
Other
5%
UK Smartphone Landscape
Source: http://bit.ly/19d2thf
Native Development
iOS
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 b...
UI Considerations
DEMO
Hello World
So… Sharing
SHARING CODE
File Linking
File Linking
DEMO
File Linking
File Linking
Pros
• Quick
Cons
• Messy code
• Progressively more
difficult to maintain as you
add implementations
• Very h...
SHARING CODE
Portable Class Libraries
Adding a PCL
Great… but
Still need platform specific code somehow…
SHARING CODE
Abstract Classes
Multiple Concrete Classes
DEMO
Abstract Classes
Abstract Classes
Pros
• Quick
• Easier to maintain
• Follows Open/Closed
principal
Cons
• Difficult to test
• Pretty infle...
SHARING CODE
Dependency Injection
Dependency Injection
• Helps separate code (Single responsibility)
• Allows you to unit test’s discrete parts of
the imple...
DEMO
PCL & DI demo
Dependency Injection
Pros
• Very loosely coupled
code (reuse)
• Unit tests are easy
• Single Responsibility
• Open/Closed
...
What are the downsides to using
Dependency Injection?
It can be dangerous for your career because it
may increase your ove...
Dependency Injection
Pros
• Very loosely coupled
code (reuse)
• Unit tests are easy
• Single Responsibility
• Open/Closed
...
Can we squeeze any more reuse
out?
MAXIMIZE UI CODE REUSE
MVVM
MVVM
Platform Specific Code
Shared Code
Demo
Improving Code Reuse in 3 easy
ways
• Heavy use of dependency injection
– Allows different implementations for different
p...
3 layers of win
MVVMCross
Xamarin
Visual Studio
Links
• http://xamarin.com/
• http://mvvmcross.wordpress.com/
• http://propertycross.com/
• https://github.com/rossdargan/...
Questions
Cross Platform Development in C# (DDDNorth 2013)
Cross Platform Development in C# (DDDNorth 2013)
Cross Platform Development in C# (DDDNorth 2013)
Upcoming SlideShare
Loading in...5
×

Cross Platform Development in C# (DDDNorth 2013)

2,090
-1

Published on

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/Talks

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,090
On Slideshare
0
From Embeds
0
Number of Embeds
43
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Cross Platform Development in C# (DDDNorth 2013)

  1. 1. Cross Platform Mobile Development in C# Ross Dargan @rossdargan
  2. 2. What I’m going to cover Target 95% of the UK mobile market in C# With maximum code re-use
  3. 3. What I’m going to cover
  4. 4. What I won’t cover The other cross platform options (http://propertycross.com/) A full walkthrough of the tooling Blackberry
  5. 5. Android 56% Windows 12% iOS 27% Blackberry 4% Other 1% Other 5% UK Smartphone Landscape Source: http://bit.ly/19d2thf
  6. 6. Native Development iOS Objective C Xcode Windows Phone C#/Visual Basic/F# Visual Studio Android Java Eclipse IntelliJ
  7. 7. Xamarin • C# and .NET for Android, iOS and Mac • Full native APIs
  8. 8. 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
  9. 9. UI Considerations
  10. 10. DEMO Hello World
  11. 11. So… Sharing
  12. 12. SHARING CODE File Linking
  13. 13. File Linking
  14. 14. DEMO File Linking
  15. 15. 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
  16. 16. SHARING CODE Portable Class Libraries
  17. 17. Adding a PCL
  18. 18. Great… but Still need platform specific code somehow…
  19. 19. SHARING CODE Abstract Classes
  20. 20. Multiple Concrete Classes
  21. 21. DEMO Abstract Classes
  22. 22. Abstract Classes Pros • Quick • Easier to maintain • Follows Open/Closed principal Cons • Difficult to test • Pretty inflexible
  23. 23. SHARING CODE Dependency Injection
  24. 24. 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
  25. 25. DEMO PCL & DI demo
  26. 26. Dependency Injection Pros • Very loosely coupled code (reuse) • Unit tests are easy • Single Responsibility • Open/Closed Cons • • •
  27. 27. 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
  28. 28. Dependency Injection Pros • Very loosely coupled code (reuse) • Unit tests are easy • Single Responsibility • Open/Closed Cons • More code • Bloated constructors
  29. 29. Can we squeeze any more reuse out?
  30. 30. MAXIMIZE UI CODE REUSE MVVM
  31. 31. MVVM Platform Specific Code Shared Code
  32. 32. Demo
  33. 33. 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
  34. 34. 3 layers of win MVVMCross Xamarin Visual Studio
  35. 35. 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/
  36. 36. Questions
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×