sharing up to 80% code for ios, android, and windows platforms, a retail app case study, roy...

47
Welcome!

Upload: xamarin

Post on 10-May-2015

3.010 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Welcome!

Page 2: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Sharing up to 80% of code building mobile apps for iOS, Android, WP8 and Windows 8

Roy CornelissenIT Architect,Info Support

per,Info Support

Marcel de VriesTechnology Manager

@marcelv

XamarinEvolve2013

Roy CornelissenIT Architect

@roycornelissen

Page 3: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 4: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 5: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 6: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 7: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 8: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 9: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Key takeaways Demos

Architecture Tips & Tricks

Page 10: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Showcase

Page 11: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

National web site, aimed at selling the “last available seats” for theatre shows for up to 4 days

No discount or auction site, but a source for inspiration for a fun night out

Order tickets from home, from a terrace or from your hotel room

Page 12: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Demo

Page 13: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

MindsetLessons we’ve learned over the years

Stuff that actually works in practiceNot only theoretically

We target iOS, Android and WindowsLeaving out Windows can give a different perspective

on reuse

Showcase: app for a retail startupCurrently being rebranded

Page 14: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

What we’ve heard the past few days

Many cross platform talks

Talks on frameworks

This session is about a real app, not

just an example

Important: we also target WindowsVery different UI paradigms, impacts code structure and

level of reuse

Page 15: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 16: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Reusable34%

Shared Logic17%Android

10%

iOS8%

Windows Phone10%

Services21%

Shared84%

Specific16%

Per App

Page 17: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 18: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Evaluate frameworks

MonoCross

MvvmCross

Roll your own

Frameworks can help speed up

development but they might also limit

your movements by (over)abstraction

Keep as light

as possible

Page 19: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

DataSerialization

Caching

SecurityAuthN/AuthZ

Encryption

Data Self Destruction

UtilitiesAnalytics

Logging

Device services

Platform Agnostic API

Application Business Logic

Platform UI

Design Patterns for Reuse

Glue together the

application layers

Page 20: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Navigation frameworks

In our experience, navigation

frameworks yield leaky abstractions.

E.g. PivotView navigation experience

is not the same as menu navigation

via UINavigationController.

Leave UI navigation device

specific

Page 21: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Windows

One pivotview

over multiple

data

representations

Page 22: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Android

Tab bar style

navigation with

separate

activities

Page 23: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 24: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Services

Model

ControllerViewModel

Etc.

GPS

Storage

Motion sensors

View

Shared?

Bridge

Shared Platform specific

Page 25: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Model Implementation

We implement the Model as a Singleton

Model Implements INotifyPropertyChanged

Easy to enlist subscribers

Facilitate automatic databinding in XAML

Model contains rich features such as filtering and

advanced selections

Easy to share logic

Page 26: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Model Implementationpublic class MainModel : INotifyPropertyChanged{

private static MainModel _model;private static object _lockHandle = new object();

// Facilitates Windows Phone app resumepublic void RestoreState(MainModel state){

_model = state;}

public static MainModel Current{

get {if (_model == null) {

_model = new MainModel();}return _model;

}}

public IEnumerable<Event> ActualEvents {get {

// E.g. Complex linq stuff}

}}

// Model Usage:

var foo = MainModel.Current.ActualEvents;

Page 27: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Check your water level

Reusable Business Logic

Device SpecificXAML / ValueConverter

Model PropertyValue Transformation

Page 28: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 29: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

public class ISKEController{

private static ISKEController _instance;private ISKEDomainServicesoap _proxy;

public static ISKEController Current{

get {if (_instance == null) {

_instance = new ISKEController();}return _instance;

}}

private void GetActualEvents (Action<object> OnSuccess, Action<Exception> OnFail){

// do some logic, or service call// use actions to report result or trigger UI action

}}

Page 30: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Shared Controller

UIViewController XAML View Activity

Web Services

SF

SF

SF

Model

GetActualEvents(Action<object> OnSuccess, Action<Exception> OnFail)

PropertyChanged(“Events”);

public void OnFailed(Exception e){

// Do something with error}

public void OnSuccess(object data){

// Do something with data// Notify user

}

Page 31: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Demo

Page 32: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 33: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

iOS

MonoTouch.CoreLocation

MonoTouch.CoreMotion

MonoTouch.AVFoundation

MonoTouch.AddressBook

MonoTouch.EventKit

Android:

Android.Hardware.Sensor

Android.Location

Android.Bluetooth

Android.Nfc

Windows Phone:

Microsoft.Devices.Sensors.Gyroscope

Microsoft.Devices.Sensors.Accelerometer

Microsoft.Devices.Sensors.Compass

Microsoft.Devices.Sensors.Motion

Page 34: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Partial classes & methods

Page 35: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

partial class A

{

// Half of the implementation

}

partial class A

{

// The other half

}

A.cs A.extra.cs

Page 36: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

partial class A

{

// Declare the method here

partial void DoSomethingEx();

public void DoSomething()

{

// Some shared logic

DoSomethingEx();

}

}

partial class A

{

// Provide the implementation here

partial void DoSomethingEx()

{

// Do something iOS specific

}

}Can be used from shared

logic

Leaves room for specific

implementation

Always private and returns

void

A.cs A.iOS.cs

Page 37: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 38: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Demo

Page 39: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Services – Use soap?

Proxy generation

Silverlight tools: it needs to run on Windows too!

What about bandwidth?

Page 40: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Services – Use REST/JSON?

WebAPI / ServiceStack

More hand coding

Cloud: Azure / Parse / Buddy

Page 41: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 42: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries
Page 43: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Cross platform version control

GitHub, BitBucket

VisualStudio.com

Work items, builds

Page 44: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Demo

Page 45: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

C# language tricks

Leverage your tools

Page 46: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

Abstractions are good

But don’t over-abstract

Don’t over-engineer

Beware of pitfalls…

Page 47: Sharing up to 80% code for iOS, Android, and Windows platforms, a Retail App Case Study, Roy Cornellisen and Marcel de Vries

@roycornelissenroycornelissen.wordpress.com

Thank [email protected]/marcelv