2. Sharing up to 80% of
code building mobile
apps for iOS, Android,
WP8 and Windows 8 Roy
Cornelissen
IT Architect,
Info Support
per,
Info Support
Marcel
de Vries
TechnologyManager
@marcelv
Xamarin
Evolve
2013
Roy
Cornelissen
ITArchitect
@roycornelissen
11. 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
13. Mindset
Lessons we’ve learned over the years
Stuff that actually works in practice
Not only theoretically
We target iOS, Android and Windows
Leaving out Windows can give a different perspective
on reuse
Showcase: app for a retail startup
Currently being rebranded
14. 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 Windows
Very different UI paradigms, impacts code structure and
level of reuse
20. 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
25. 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
26. Model Implementation
public class MainModel : INotifyPropertyChanged
{
private static MainModel _model;
private static object _lockHandle = new object();
// Facilitates Windows Phone app resume
public 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;
27. Check your water level
Reusable Business Logic
Device Specific
XAML / ValueConverter
Model Property
Value Transformation
29. 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
}
}
30. Shared Controller
UIViewController XAML View Activity
Web Services
S
F
S
F
S
F
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
}
35. partial class A
{
// Half of the implementation
}
partial class A
{
// The other half
}
A.cs A.extra.cs
36. 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