SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
( And Halp clients )
Code Reuse
with MVVM
1Dienstag, 16. April 13
High-level talk, mostly focused on Apple (because that’s my forté), but most of the concepts here are generally applicable to all
platforms (and that’s exactly the point).
2Dienstag, 16. April 13
But first, let me introduce myself and the other guys who worked on this app.
Who
Justin Spahr-Summers - @jspahrsummers
Paul Betts - @xpaulbettsx
Josh Vera - @joshvera
Josh Abernathy - @joshaber
3Dienstag, 16. April 13
I work on GitHub for Mac. I primarily write Objective-C code, but I also regularly code in Haskell as well. Paul works on GitHub for
Windows (written in C#), Josh Vera works on an internal talks app written in Objective-C, and Josh Abernathy also works on
GitHub for Mac.
There’s quite a large diversity of experience between us, and I’ve included these guys on here because they all had something do
with this presentation today.
What
Write unit tests for UI behavior
Example: our native Halp apps
Maximize code reuse across platforms,
but keep 100% native UI
4Dienstag, 16. April 13
Halp is an internal app that we use at GitHub for user support (but more on that later).
Why
“Build software better, together.”
At GitHub, we ask: “What is the best way to build software?”
Philosophies, tools, practices
5Dienstag, 16. April 13
One of the questions _we_ work on every day is, “What’s the best way to build native user interfaces?”
View Model
Controller
How
( According to  )
6Dienstag, 16. April 13
As recommended by Apple, Cocoa applications are typically designed using Model-View-Controller, shown here. The solid lines
represent direct references; the dashed lines represent indirect references (like observation).
View ViewModel Model
How
( According to us )
7Dienstag, 16. April 13
At GitHub, we much prefer to use Model-View-ViewModel, shown here. If you haven’t been introduced to MVVM, here’s a quick
explanation:
The ViewModel replaces the role of the (View) Controller, but the VM doesn’t have a direct reference to the view like a controller
would. Instead, the VM communicates to the V with a system of bindings. … For example, If you want to show a loading spinner,
the view model might have a boolean property which indicates whether to show it. The view would observe that property for
changes, and hide/show the spinner in response.
Meh. So what?
8Dienstag, 16. April 13
This might just seem like a way to restate the MVC pattern, but the reversed relationship between the View and the ViewModel
offers huge benefits.
Benefits of MVVM
✓ View models are testable, no UI
automation required
✓ View models can do model-like
things (e.g., serialization)
9Dienstag, 16. April 13
Traditionally, view controllers rarely get unit tested in Cocoa, simply because it’s such a pain to write a controller that doesn’t
depend on having a view (or, alternatively, to set up a valid view in unit tests). Since the VM doesn’t even know about view
objects, they can be tested without a GUI at all!
Serialization: for example, to save and restore the state of your UI, you can just save and restore your VM hierarchy. Doing this in
MVC would require a separate set of “view state” objects – which are basically view models anyways!
Also, portability!
10Dienstag, 16. April 13
I mentioned code sharing between platforms, so let’s take a look at how that works in MVC and MVVM. Naturally, we’ll assume
the use of Xamarin for both.
Model-View-Controller
View Model
Controller
11Dienstag, 16. April 13
The blue circle here is the code we can share across platforms.
What’s Shared?
Xamarin means we only have to write
our models once, in .NET
Any networking and domain logic
is trivially cross-platform
12Dienstag, 16. April 13
What’s Unique?
We want 100% native UI on each
platform – no Qt, GTK+, or Java
To do this, we need to create views
specific to each platform
13Dienstag, 16. April 13
This makes sense and is perfectly appropriate. Sharing view code leads to lower-quality apps which cater to the lowest common
denominator and ignore each platform’s individual UI conventions.
What’s Unshared?
Logic for when to fetch
resources from the API
UI behaviors
(e.g., how to populate lists, or when to show spinners)
14Dienstag, 16. April 13
If we follow MVC, we’re also rewriting this logic for each platform (as part of our controller layer), even though it’s not platform-
specific. This is code that _should_ be shared, but isn’t.
Now, let’s contrast that with MVVM.
Model-View-ViewModel
View ViewModel Model
15Dienstag, 16. April 13
Interestingly, because the VM doesn’t reference the view (or any UI) directly, it becomes reusable across platforms. The VM
describes only how the UI should update and respond to user actions – not how it should look. Multiple types of view can be
created for one view model, and each can look completely different, but most of the underlying logic will remain the same.
If we’re using Xamarin, we can now write most of our model _and view model_ code just once. The VM implements most of our
UI behavior, like…
View Models Handle…
Loading content the UI needs
Hiding and showing content
Date, number, and string formatting
Responding to the user
16Dienstag, 16. April 13
There are just some typical use cases, not a complete list.
Loading: note that the view model is not actually responsible for the details of persistence, networking, etc. It’s only responsible
for communicating with whatever that layer is, _based on_ what the UI needs to show at any point in time.
Halp!
17Dienstag, 16. April 13
That’s most of the abstract stuff. I want to switch gears for a moment here and talk about our support tool, and the native clients
we’re implementing using MVVM and Xamarin.
18Dienstag, 16. April 13
This is the web app that we use for user support. It lets us triage our users’ emails and get them to the right people as quickly as
possible. Supportocats and developers can reply to messages, bring other people into the discussion, cross-link to other internal
resources, etc.
Here, we’re looking at a discussion thread in the Technical inbox.
19Dienstag, 16. April 13
GitHub is based in San Francisco, but about half of GitHub works remotely on a regular basis (I myself work from Seattle). Twice
every year, all of the company meets in SF for GitHub Summit.
Our last summit was earlier this year, and a few of us wanted to spend our Hack Day working on a native client for Halp. We
decided to use Xamarin to share code between our different desired platforms, and reduce the development and maintenance
effort that would otherwise be involved in each one. We started the iOS client that day, and a Mac client since.
Mac App Goals
Watch a specific inbox for new messages
Display a message count in the menu bar
View the messages in any inbox
(but especially the watched one)
20Dienstag, 16. April 13
This is what we want to do for our Mac client.
We’ve started on a prototype. It’s still very premature, so it doesn’t do much yet.
iPhone App Goals
View the messages in any inbox
Read any message
Triage messages by moving to another inbox
21Dienstag, 16. April 13
And this is what we want to do for our iPhone client. (An iPad client would be very similar as well.)
This one’s a bit further along, but still pretty rough around the edges. All the data here is loaded from the API and cached locally
by the app.
(Demo)
22Dienstag, 16. April 13
Shared Behaviors
Showing inboxes and messages
Requesting and caching data
Showing loading indicators
23Dienstag, 16. April 13
By no coincidence, these are the behaviors implemented by our cross-platform view models.
Let’s take a look at the code. (ViewModels, MenubarController?, PopoverController?, TableSources)
(Code)
24Dienstag, 16. April 13
Let’s get real.
25Dienstag, 16. April 13
Cocoa wasn’t really designed with MVVM in mind. Here are some minor obstacles you may encounter.
View Controllers
Layout, animations, device rotation,
view transitions
Seems like view controllers are
actually part of the view layer!
26Dienstag, 16. April 13
OS X and iOS both have view (or window) controllers, which can make MVVM confusing at first glance. Once you look deeper,
though, it’s not much of a problem at all.
View Controllers
NSViewController doesn’t do much
UIViewController is quite powerful
Between views and view controllers,
use the easiest one
27Dienstag, 16. April 13
Basically, use the class that will make implementing your view layer easiest. On OS X, you’ll probably just want NSView, since
NSViewController is relatively useless. On iOS, you’ll probably want UIViewController, so you can handle rotation, navigation, etc.
No matter what you decide to use for your UI, you’ll still have a ViewModel.
Data Binding
Notifications are too general,
and have global scope
Key-Value Observing is difficult
to use and comes with boilerplate
28Dienstag, 16. April 13
It’s hard to write the indirect relationship from the ViewModel to the View without a powerful system of bindings. Cocoa (and, by
extension, Xamarin.Mac and Xamarin.iOS) offers a couple solutions, but they’re woefully inadequate.
In addition to these individual problems, neither supports automatic transformation or filtering of bound values. Worse, both are
specific to Cocoa, so our V <> VM bindings will look quite different from our VM <> M bindings (which should be cross-
platform).
Data Binding
In Objective-C, we wrote a
framework called ReactiveCocoa
In C#, we have Reactive Extensions
and our ReactiveUI framework
29Dienstag, 16. April 13
Reactive Extensions (or Rx) is an implementation of Functional Reactive Programming, which is unfortunately beyond the scope
of this talk, but there are lots of great resources for learning more about it.
ReactiveUI is an MVVM framework for .NET. One of its major features is an API for declarative data bindings, built on top of Rx.
30Dienstag, 16. April 13
GitHub for Mac uses ReactiveCocoa to implement MVVM at a large scale. The app itself is written in Objective-C, but the lessons
we’ve learned about MVVM are just as applicable to Xamarin.Mac and Xamarin.iOS.
Linkage
Rx – introtorx.com
ReactiveUI – reactiveui.net
github:mac – mac.github.com
github:windows – windows.github.com
31Dienstag, 16. April 13

Contenu connexe

Tendances

Cordova: APIs and instruments
Cordova: APIs and instrumentsCordova: APIs and instruments
Cordova: APIs and instrumentsIvano Malavolta
 
C# Security Testing and Debugging
C# Security Testing and DebuggingC# Security Testing and Debugging
C# Security Testing and DebuggingRich Helton
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101Rich Helton
 
Embedding Web UIs in your Eclipse application
Embedding Web UIs in your Eclipse applicationEmbedding Web UIs in your Eclipse application
Embedding Web UIs in your Eclipse applicationBoris Bokowski
 
Cordova + Ionic + MobileFirst
Cordova + Ionic + MobileFirstCordova + Ionic + MobileFirst
Cordova + Ionic + MobileFirstRaymond Camden
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java SlidesVinit Vyas
 
Xamarin.iOS introduction
Xamarin.iOS introductionXamarin.iOS introduction
Xamarin.iOS introductionGuido Magrin
 
Spring Framework
Spring FrameworkSpring Framework
Spring Frameworknomykk
 
Eclipse Plug-in Develompent Tips And Tricks
Eclipse Plug-in Develompent Tips And TricksEclipse Plug-in Develompent Tips And Tricks
Eclipse Plug-in Develompent Tips And TricksChris Aniszczyk
 
Entity frameworks101
Entity frameworks101Entity frameworks101
Entity frameworks101Rich Helton
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Mikkel Flindt Heisterberg
 
Spring framework
Spring frameworkSpring framework
Spring frameworkvietduc17
 
iPhone Coding For Web Developers
iPhone Coding For Web DevelopersiPhone Coding For Web Developers
iPhone Coding For Web DevelopersMatt Biddulph
 

Tendances (19)

Cordova: APIs and instruments
Cordova: APIs and instrumentsCordova: APIs and instruments
Cordova: APIs and instruments
 
C# Security Testing and Debugging
C# Security Testing and DebuggingC# Security Testing and Debugging
C# Security Testing and Debugging
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
Android programming-basics
Android programming-basicsAndroid programming-basics
Android programming-basics
 
Embedding Web UIs in your Eclipse application
Embedding Web UIs in your Eclipse applicationEmbedding Web UIs in your Eclipse application
Embedding Web UIs in your Eclipse application
 
Cordova + Ionic + MobileFirst
Cordova + Ionic + MobileFirstCordova + Ionic + MobileFirst
Cordova + Ionic + MobileFirst
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
 
Xamarin.iOS introduction
Xamarin.iOS introductionXamarin.iOS introduction
Xamarin.iOS introduction
 
Apache cordova
Apache cordovaApache cordova
Apache cordova
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Eclipse Plug-in Develompent Tips And Tricks
Eclipse Plug-in Develompent Tips And TricksEclipse Plug-in Develompent Tips And Tricks
Eclipse Plug-in Develompent Tips And Tricks
 
Entity frameworks101
Entity frameworks101Entity frameworks101
Entity frameworks101
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)
 
Apache ant
Apache antApache ant
Apache ant
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
iPhone Coding For Web Developers
iPhone Coding For Web DevelopersiPhone Coding For Web Developers
iPhone Coding For Web Developers
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 

En vedette

RubyからC#を扱う
RubyからC#を扱うRubyからC#を扱う
RubyからC#を扱う107steps
 
日々の面倒をプログラミングで解決!【入門編】
日々の面倒をプログラミングで解決!【入門編】日々の面倒をプログラミングで解決!【入門編】
日々の面倒をプログラミングで解決!【入門編】Hiroshi Oyamada
 
Keep yourself up to date
Keep yourself up to dateKeep yourself up to date
Keep yourself up to date信之 岩永
 
Manual tecnico primer parcial
Manual tecnico primer parcialManual tecnico primer parcial
Manual tecnico primer parcialDamaris Raquel
 
Bs25999 2 advisory board
Bs25999 2 advisory boardBs25999 2 advisory board
Bs25999 2 advisory boardchrisggreen
 
Planeacion quimicayentorno
Planeacion quimicayentornoPlaneacion quimicayentorno
Planeacion quimicayentornoblognms
 
Danteyladivinacomedia 120702121455-phpapp01
Danteyladivinacomedia 120702121455-phpapp01Danteyladivinacomedia 120702121455-phpapp01
Danteyladivinacomedia 120702121455-phpapp01Aldo Martín Livia Reyes
 
Your Marketing Toolkit:Low-Cost/No Cost Business Tools That Will Make You Mor...
Your Marketing Toolkit:Low-Cost/No Cost Business Tools That Will Make You Mor...Your Marketing Toolkit:Low-Cost/No Cost Business Tools That Will Make You Mor...
Your Marketing Toolkit:Low-Cost/No Cost Business Tools That Will Make You Mor...We Coach The Pros
 
Instituto Universitario de Posgrado
Instituto Universitario de PosgradoInstituto Universitario de Posgrado
Instituto Universitario de Posgradoguest428e034d
 
HOW CAN I SPY ON SOMEONES FACEBOOK
HOW CAN I SPY ON SOMEONES FACEBOOK HOW CAN I SPY ON SOMEONES FACEBOOK
HOW CAN I SPY ON SOMEONES FACEBOOK Jane_Robert
 
Ayudas para la mejora de la producción y comercialización de la miel en la Co...
Ayudas para la mejora de la producción y comercialización de la miel en la Co...Ayudas para la mejora de la producción y comercialización de la miel en la Co...
Ayudas para la mejora de la producción y comercialización de la miel en la Co...CEDER Merindades
 
Catálogo Productos-piscina.com
Catálogo Productos-piscina.comCatálogo Productos-piscina.com
Catálogo Productos-piscina.comProductos piscina
 
Decreto de consagracion del ecuador
Decreto de consagracion del ecuadorDecreto de consagracion del ecuador
Decreto de consagracion del ecuadorMary Cecily
 
OAuth 2.0 und OpenId Connect
OAuth 2.0 und OpenId ConnectOAuth 2.0 und OpenId Connect
OAuth 2.0 und OpenId ConnectManfred Steyer
 
Descartes
DescartesDescartes
DescartesAndeka
 

En vedette (20)

RubyからC#を扱う
RubyからC#を扱うRubyからC#を扱う
RubyからC#を扱う
 
Interaction channel
Interaction channelInteraction channel
Interaction channel
 
日々の面倒をプログラミングで解決!【入門編】
日々の面倒をプログラミングで解決!【入門編】日々の面倒をプログラミングで解決!【入門編】
日々の面倒をプログラミングで解決!【入門編】
 
広がる .Net
広がる .Net広がる .Net
広がる .Net
 
Keep yourself up to date
Keep yourself up to dateKeep yourself up to date
Keep yourself up to date
 
Manual tecnico primer parcial
Manual tecnico primer parcialManual tecnico primer parcial
Manual tecnico primer parcial
 
Bs25999 2 advisory board
Bs25999 2 advisory boardBs25999 2 advisory board
Bs25999 2 advisory board
 
Planeacion quimicayentorno
Planeacion quimicayentornoPlaneacion quimicayentorno
Planeacion quimicayentorno
 
Danteyladivinacomedia 120702121455-phpapp01
Danteyladivinacomedia 120702121455-phpapp01Danteyladivinacomedia 120702121455-phpapp01
Danteyladivinacomedia 120702121455-phpapp01
 
Your Marketing Toolkit:Low-Cost/No Cost Business Tools That Will Make You Mor...
Your Marketing Toolkit:Low-Cost/No Cost Business Tools That Will Make You Mor...Your Marketing Toolkit:Low-Cost/No Cost Business Tools That Will Make You Mor...
Your Marketing Toolkit:Low-Cost/No Cost Business Tools That Will Make You Mor...
 
Ancianos
AncianosAncianos
Ancianos
 
Instituto Universitario de Posgrado
Instituto Universitario de PosgradoInstituto Universitario de Posgrado
Instituto Universitario de Posgrado
 
HOW CAN I SPY ON SOMEONES FACEBOOK
HOW CAN I SPY ON SOMEONES FACEBOOK HOW CAN I SPY ON SOMEONES FACEBOOK
HOW CAN I SPY ON SOMEONES FACEBOOK
 
Ayudas para la mejora de la producción y comercialización de la miel en la Co...
Ayudas para la mejora de la producción y comercialización de la miel en la Co...Ayudas para la mejora de la producción y comercialización de la miel en la Co...
Ayudas para la mejora de la producción y comercialización de la miel en la Co...
 
Revista Regio nr.30 iulie 2014
Revista Regio nr.30 iulie 2014Revista Regio nr.30 iulie 2014
Revista Regio nr.30 iulie 2014
 
Progettare antifurto a norme Cei 79 3 Diakron
Progettare antifurto a norme Cei 79 3 DiakronProgettare antifurto a norme Cei 79 3 Diakron
Progettare antifurto a norme Cei 79 3 Diakron
 
Catálogo Productos-piscina.com
Catálogo Productos-piscina.comCatálogo Productos-piscina.com
Catálogo Productos-piscina.com
 
Decreto de consagracion del ecuador
Decreto de consagracion del ecuadorDecreto de consagracion del ecuador
Decreto de consagracion del ecuador
 
OAuth 2.0 und OpenId Connect
OAuth 2.0 und OpenId ConnectOAuth 2.0 und OpenId Connect
OAuth 2.0 und OpenId Connect
 
Descartes
DescartesDescartes
Descartes
 

Similaire à GitHub halp app - Minimizing platform-specific code with MVVM - Justin Spahr-Summers

What is Codename One - Transcript.pdf
What is Codename One - Transcript.pdfWhat is Codename One - Transcript.pdf
What is Codename One - Transcript.pdfShaiAlmog1
 
9 reasons why programmers should learn react native
9 reasons why programmers should learn react native9 reasons why programmers should learn react native
9 reasons why programmers should learn react nativeReact Sharing
 
Common Missteps in Cross-Platform Development.pdf
Common Missteps in Cross-Platform Development.pdfCommon Missteps in Cross-Platform Development.pdf
Common Missteps in Cross-Platform Development.pdfPridesys IT Ltd.
 
Introduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning SimpleIntroduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning SimpleSandeep Hijam
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Manoj Ellappan
 
Man in-the-browser-in-depth-report
Man in-the-browser-in-depth-reportMan in-the-browser-in-depth-report
Man in-the-browser-in-depth-reportHai Nguyen
 
Microservice pitfalls
Microservice pitfalls Microservice pitfalls
Microservice pitfalls Mite Mitreski
 
Viacheslav Eremin interview about DOT NET (eng lang)
Viacheslav Eremin interview about DOT NET (eng lang)Viacheslav Eremin interview about DOT NET (eng lang)
Viacheslav Eremin interview about DOT NET (eng lang)Viacheslav Eremin
 
Why You Should Use MERN Stack for Startup Apps?
Why You Should Use MERN Stack for Startup Apps?Why You Should Use MERN Stack for Startup Apps?
Why You Should Use MERN Stack for Startup Apps?Pixel Crayons
 
Microservices and functional programming
Microservices and functional programmingMicroservices and functional programming
Microservices and functional programmingMichael Neale
 
Enterprise ipad Development with notes
Enterprise ipad Development with notesEnterprise ipad Development with notes
Enterprise ipad Development with notesjaxarcsig
 
Elm Detroit 9/7/17 - Planting Seeds with Elm
Elm Detroit 9/7/17 - Planting Seeds with ElmElm Detroit 9/7/17 - Planting Seeds with Elm
Elm Detroit 9/7/17 - Planting Seeds with ElmElm Detroit
 
How, When, and Why to Patch a Module
How, When, and Why to Patch a Module How, When, and Why to Patch a Module
How, When, and Why to Patch a Module Phase2
 
Reactive design: languages, and paradigms
Reactive design: languages, and paradigmsReactive design: languages, and paradigms
Reactive design: languages, and paradigmsDean Wampler
 
Top 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppTop 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppKaty Slemon
 
A Brief Note On Asp.Net And Cloud Computing Essay
A Brief Note On Asp.Net And Cloud Computing EssayA Brief Note On Asp.Net And Cloud Computing Essay
A Brief Note On Asp.Net And Cloud Computing EssayLanate Drummond
 
Introduction to meteor
Introduction to meteorIntroduction to meteor
Introduction to meteorNodeXperts
 

Similaire à GitHub halp app - Minimizing platform-specific code with MVVM - Justin Spahr-Summers (20)

What is Codename One - Transcript.pdf
What is Codename One - Transcript.pdfWhat is Codename One - Transcript.pdf
What is Codename One - Transcript.pdf
 
9 reasons why programmers should learn react native
9 reasons why programmers should learn react native9 reasons why programmers should learn react native
9 reasons why programmers should learn react native
 
Common Missteps in Cross-Platform Development.pdf
Common Missteps in Cross-Platform Development.pdfCommon Missteps in Cross-Platform Development.pdf
Common Missteps in Cross-Platform Development.pdf
 
Introduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning SimpleIntroduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning Simple
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
 
Man in-the-browser-in-depth-report
Man in-the-browser-in-depth-reportMan in-the-browser-in-depth-report
Man in-the-browser-in-depth-report
 
Microservice pitfalls
Microservice pitfalls Microservice pitfalls
Microservice pitfalls
 
Viacheslav Eremin interview about DOT NET (eng lang)
Viacheslav Eremin interview about DOT NET (eng lang)Viacheslav Eremin interview about DOT NET (eng lang)
Viacheslav Eremin interview about DOT NET (eng lang)
 
MyReplayInZen
MyReplayInZenMyReplayInZen
MyReplayInZen
 
Developers survival-guide
Developers survival-guideDevelopers survival-guide
Developers survival-guide
 
Why You Should Use MERN Stack for Startup Apps?
Why You Should Use MERN Stack for Startup Apps?Why You Should Use MERN Stack for Startup Apps?
Why You Should Use MERN Stack for Startup Apps?
 
Microservices and functional programming
Microservices and functional programmingMicroservices and functional programming
Microservices and functional programming
 
Enterprise ipad Development with notes
Enterprise ipad Development with notesEnterprise ipad Development with notes
Enterprise ipad Development with notes
 
Elm Detroit 9/7/17 - Planting Seeds with Elm
Elm Detroit 9/7/17 - Planting Seeds with ElmElm Detroit 9/7/17 - Planting Seeds with Elm
Elm Detroit 9/7/17 - Planting Seeds with Elm
 
How, When, and Why to Patch a Module
How, When, and Why to Patch a Module How, When, and Why to Patch a Module
How, When, and Why to Patch a Module
 
Reactive design: languages, and paradigms
Reactive design: languages, and paradigmsReactive design: languages, and paradigms
Reactive design: languages, and paradigms
 
Top 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppTop 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular App
 
A Brief Note On Asp.Net And Cloud Computing Essay
A Brief Note On Asp.Net And Cloud Computing EssayA Brief Note On Asp.Net And Cloud Computing Essay
A Brief Note On Asp.Net And Cloud Computing Essay
 
Introduction to meteor
Introduction to meteorIntroduction to meteor
Introduction to meteor
 
Codename one
Codename oneCodename one
Codename one
 

Plus de Xamarin

Xamarin University Presents: Building Your First Intelligent App with Xamarin...
Xamarin University Presents: Building Your First Intelligent App with Xamarin...Xamarin University Presents: Building Your First Intelligent App with Xamarin...
Xamarin University Presents: Building Your First Intelligent App with Xamarin...Xamarin
 
Xamarin University Presents: Ship Better Apps with Visual Studio App Center
Xamarin University Presents: Ship Better Apps with Visual Studio App CenterXamarin University Presents: Ship Better Apps with Visual Studio App Center
Xamarin University Presents: Ship Better Apps with Visual Studio App CenterXamarin
 
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for XamarinGet the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for XamarinXamarin
 
Get the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for XamarinGet the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for XamarinXamarin
 
Creative Hacking: Delivering React Native App A/B Testing Using CodePush
Creative Hacking: Delivering React Native App A/B Testing Using CodePushCreative Hacking: Delivering React Native App A/B Testing Using CodePush
Creative Hacking: Delivering React Native App A/B Testing Using CodePushXamarin
 
Build Better Games with Unity and Microsoft Azure
Build Better Games with Unity and Microsoft AzureBuild Better Games with Unity and Microsoft Azure
Build Better Games with Unity and Microsoft AzureXamarin
 
Exploring UrhoSharp 3D with Xamarin Workbooks
Exploring UrhoSharp 3D with Xamarin WorkbooksExploring UrhoSharp 3D with Xamarin Workbooks
Exploring UrhoSharp 3D with Xamarin WorkbooksXamarin
 
Desktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
Desktop Developer’s Guide to Mobile with Visual Studio Tools for XamarinDesktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
Desktop Developer’s Guide to Mobile with Visual Studio Tools for XamarinXamarin
 
Developer’s Intro to Azure Machine Learning
Developer’s Intro to Azure Machine LearningDeveloper’s Intro to Azure Machine Learning
Developer’s Intro to Azure Machine LearningXamarin
 
Customizing Xamarin.Forms UI
Customizing Xamarin.Forms UICustomizing Xamarin.Forms UI
Customizing Xamarin.Forms UIXamarin
 
Session 4 - Xamarin Partner Program, Events and Resources
Session 4 - Xamarin Partner Program, Events and ResourcesSession 4 - Xamarin Partner Program, Events and Resources
Session 4 - Xamarin Partner Program, Events and ResourcesXamarin
 
Session 3 - Driving Mobile Growth and Profitability
Session 3 - Driving Mobile Growth and ProfitabilitySession 3 - Driving Mobile Growth and Profitability
Session 3 - Driving Mobile Growth and ProfitabilityXamarin
 
Session 2 - Emerging Technologies in your Mobile Practice
Session 2 - Emerging Technologies in your Mobile PracticeSession 2 - Emerging Technologies in your Mobile Practice
Session 2 - Emerging Technologies in your Mobile PracticeXamarin
 
Session 1 - Transformative Opportunities in Mobile and Cloud
Session 1 - Transformative Opportunities in Mobile and Cloud Session 1 - Transformative Opportunities in Mobile and Cloud
Session 1 - Transformative Opportunities in Mobile and Cloud Xamarin
 
SkiaSharp Graphics for Xamarin.Forms
SkiaSharp Graphics for Xamarin.FormsSkiaSharp Graphics for Xamarin.Forms
SkiaSharp Graphics for Xamarin.FormsXamarin
 
Building Games for iOS, macOS, and tvOS with Visual Studio and Azure
Building Games for iOS, macOS, and tvOS with Visual Studio and AzureBuilding Games for iOS, macOS, and tvOS with Visual Studio and Azure
Building Games for iOS, macOS, and tvOS with Visual Studio and AzureXamarin
 
Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017Xamarin
 
Connected Mobile Apps with Microsoft Azure
Connected Mobile Apps with Microsoft AzureConnected Mobile Apps with Microsoft Azure
Connected Mobile Apps with Microsoft AzureXamarin
 
Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017Xamarin
 
Building Your First iOS App with Xamarin for Visual Studio
Building Your First iOS App with Xamarin for Visual StudioBuilding Your First iOS App with Xamarin for Visual Studio
Building Your First iOS App with Xamarin for Visual StudioXamarin
 

Plus de Xamarin (20)

Xamarin University Presents: Building Your First Intelligent App with Xamarin...
Xamarin University Presents: Building Your First Intelligent App with Xamarin...Xamarin University Presents: Building Your First Intelligent App with Xamarin...
Xamarin University Presents: Building Your First Intelligent App with Xamarin...
 
Xamarin University Presents: Ship Better Apps with Visual Studio App Center
Xamarin University Presents: Ship Better Apps with Visual Studio App CenterXamarin University Presents: Ship Better Apps with Visual Studio App Center
Xamarin University Presents: Ship Better Apps with Visual Studio App Center
 
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for XamarinGet the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
 
Get the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for XamarinGet the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
 
Creative Hacking: Delivering React Native App A/B Testing Using CodePush
Creative Hacking: Delivering React Native App A/B Testing Using CodePushCreative Hacking: Delivering React Native App A/B Testing Using CodePush
Creative Hacking: Delivering React Native App A/B Testing Using CodePush
 
Build Better Games with Unity and Microsoft Azure
Build Better Games with Unity and Microsoft AzureBuild Better Games with Unity and Microsoft Azure
Build Better Games with Unity and Microsoft Azure
 
Exploring UrhoSharp 3D with Xamarin Workbooks
Exploring UrhoSharp 3D with Xamarin WorkbooksExploring UrhoSharp 3D with Xamarin Workbooks
Exploring UrhoSharp 3D with Xamarin Workbooks
 
Desktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
Desktop Developer’s Guide to Mobile with Visual Studio Tools for XamarinDesktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
Desktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
 
Developer’s Intro to Azure Machine Learning
Developer’s Intro to Azure Machine LearningDeveloper’s Intro to Azure Machine Learning
Developer’s Intro to Azure Machine Learning
 
Customizing Xamarin.Forms UI
Customizing Xamarin.Forms UICustomizing Xamarin.Forms UI
Customizing Xamarin.Forms UI
 
Session 4 - Xamarin Partner Program, Events and Resources
Session 4 - Xamarin Partner Program, Events and ResourcesSession 4 - Xamarin Partner Program, Events and Resources
Session 4 - Xamarin Partner Program, Events and Resources
 
Session 3 - Driving Mobile Growth and Profitability
Session 3 - Driving Mobile Growth and ProfitabilitySession 3 - Driving Mobile Growth and Profitability
Session 3 - Driving Mobile Growth and Profitability
 
Session 2 - Emerging Technologies in your Mobile Practice
Session 2 - Emerging Technologies in your Mobile PracticeSession 2 - Emerging Technologies in your Mobile Practice
Session 2 - Emerging Technologies in your Mobile Practice
 
Session 1 - Transformative Opportunities in Mobile and Cloud
Session 1 - Transformative Opportunities in Mobile and Cloud Session 1 - Transformative Opportunities in Mobile and Cloud
Session 1 - Transformative Opportunities in Mobile and Cloud
 
SkiaSharp Graphics for Xamarin.Forms
SkiaSharp Graphics for Xamarin.FormsSkiaSharp Graphics for Xamarin.Forms
SkiaSharp Graphics for Xamarin.Forms
 
Building Games for iOS, macOS, and tvOS with Visual Studio and Azure
Building Games for iOS, macOS, and tvOS with Visual Studio and AzureBuilding Games for iOS, macOS, and tvOS with Visual Studio and Azure
Building Games for iOS, macOS, and tvOS with Visual Studio and Azure
 
Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017
 
Connected Mobile Apps with Microsoft Azure
Connected Mobile Apps with Microsoft AzureConnected Mobile Apps with Microsoft Azure
Connected Mobile Apps with Microsoft Azure
 
Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017
 
Building Your First iOS App with Xamarin for Visual Studio
Building Your First iOS App with Xamarin for Visual StudioBuilding Your First iOS App with Xamarin for Visual Studio
Building Your First iOS App with Xamarin for Visual Studio
 

Dernier

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Dernier (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 

GitHub halp app - Minimizing platform-specific code with MVVM - Justin Spahr-Summers

  • 1. ( And Halp clients ) Code Reuse with MVVM 1Dienstag, 16. April 13 High-level talk, mostly focused on Apple (because that’s my forté), but most of the concepts here are generally applicable to all platforms (and that’s exactly the point).
  • 2. 2Dienstag, 16. April 13 But first, let me introduce myself and the other guys who worked on this app.
  • 3. Who Justin Spahr-Summers - @jspahrsummers Paul Betts - @xpaulbettsx Josh Vera - @joshvera Josh Abernathy - @joshaber 3Dienstag, 16. April 13 I work on GitHub for Mac. I primarily write Objective-C code, but I also regularly code in Haskell as well. Paul works on GitHub for Windows (written in C#), Josh Vera works on an internal talks app written in Objective-C, and Josh Abernathy also works on GitHub for Mac. There’s quite a large diversity of experience between us, and I’ve included these guys on here because they all had something do with this presentation today.
  • 4. What Write unit tests for UI behavior Example: our native Halp apps Maximize code reuse across platforms, but keep 100% native UI 4Dienstag, 16. April 13 Halp is an internal app that we use at GitHub for user support (but more on that later).
  • 5. Why “Build software better, together.” At GitHub, we ask: “What is the best way to build software?” Philosophies, tools, practices 5Dienstag, 16. April 13 One of the questions _we_ work on every day is, “What’s the best way to build native user interfaces?”
  • 6. View Model Controller How ( According to  ) 6Dienstag, 16. April 13 As recommended by Apple, Cocoa applications are typically designed using Model-View-Controller, shown here. The solid lines represent direct references; the dashed lines represent indirect references (like observation).
  • 7. View ViewModel Model How ( According to us ) 7Dienstag, 16. April 13 At GitHub, we much prefer to use Model-View-ViewModel, shown here. If you haven’t been introduced to MVVM, here’s a quick explanation: The ViewModel replaces the role of the (View) Controller, but the VM doesn’t have a direct reference to the view like a controller would. Instead, the VM communicates to the V with a system of bindings. … For example, If you want to show a loading spinner, the view model might have a boolean property which indicates whether to show it. The view would observe that property for changes, and hide/show the spinner in response.
  • 8. Meh. So what? 8Dienstag, 16. April 13 This might just seem like a way to restate the MVC pattern, but the reversed relationship between the View and the ViewModel offers huge benefits.
  • 9. Benefits of MVVM ✓ View models are testable, no UI automation required ✓ View models can do model-like things (e.g., serialization) 9Dienstag, 16. April 13 Traditionally, view controllers rarely get unit tested in Cocoa, simply because it’s such a pain to write a controller that doesn’t depend on having a view (or, alternatively, to set up a valid view in unit tests). Since the VM doesn’t even know about view objects, they can be tested without a GUI at all! Serialization: for example, to save and restore the state of your UI, you can just save and restore your VM hierarchy. Doing this in MVC would require a separate set of “view state” objects – which are basically view models anyways!
  • 10. Also, portability! 10Dienstag, 16. April 13 I mentioned code sharing between platforms, so let’s take a look at how that works in MVC and MVVM. Naturally, we’ll assume the use of Xamarin for both.
  • 11. Model-View-Controller View Model Controller 11Dienstag, 16. April 13 The blue circle here is the code we can share across platforms.
  • 12. What’s Shared? Xamarin means we only have to write our models once, in .NET Any networking and domain logic is trivially cross-platform 12Dienstag, 16. April 13
  • 13. What’s Unique? We want 100% native UI on each platform – no Qt, GTK+, or Java To do this, we need to create views specific to each platform 13Dienstag, 16. April 13 This makes sense and is perfectly appropriate. Sharing view code leads to lower-quality apps which cater to the lowest common denominator and ignore each platform’s individual UI conventions.
  • 14. What’s Unshared? Logic for when to fetch resources from the API UI behaviors (e.g., how to populate lists, or when to show spinners) 14Dienstag, 16. April 13 If we follow MVC, we’re also rewriting this logic for each platform (as part of our controller layer), even though it’s not platform- specific. This is code that _should_ be shared, but isn’t. Now, let’s contrast that with MVVM.
  • 15. Model-View-ViewModel View ViewModel Model 15Dienstag, 16. April 13 Interestingly, because the VM doesn’t reference the view (or any UI) directly, it becomes reusable across platforms. The VM describes only how the UI should update and respond to user actions – not how it should look. Multiple types of view can be created for one view model, and each can look completely different, but most of the underlying logic will remain the same. If we’re using Xamarin, we can now write most of our model _and view model_ code just once. The VM implements most of our UI behavior, like…
  • 16. View Models Handle… Loading content the UI needs Hiding and showing content Date, number, and string formatting Responding to the user 16Dienstag, 16. April 13 There are just some typical use cases, not a complete list. Loading: note that the view model is not actually responsible for the details of persistence, networking, etc. It’s only responsible for communicating with whatever that layer is, _based on_ what the UI needs to show at any point in time.
  • 17. Halp! 17Dienstag, 16. April 13 That’s most of the abstract stuff. I want to switch gears for a moment here and talk about our support tool, and the native clients we’re implementing using MVVM and Xamarin.
  • 18. 18Dienstag, 16. April 13 This is the web app that we use for user support. It lets us triage our users’ emails and get them to the right people as quickly as possible. Supportocats and developers can reply to messages, bring other people into the discussion, cross-link to other internal resources, etc. Here, we’re looking at a discussion thread in the Technical inbox.
  • 19. 19Dienstag, 16. April 13 GitHub is based in San Francisco, but about half of GitHub works remotely on a regular basis (I myself work from Seattle). Twice every year, all of the company meets in SF for GitHub Summit. Our last summit was earlier this year, and a few of us wanted to spend our Hack Day working on a native client for Halp. We decided to use Xamarin to share code between our different desired platforms, and reduce the development and maintenance effort that would otherwise be involved in each one. We started the iOS client that day, and a Mac client since.
  • 20. Mac App Goals Watch a specific inbox for new messages Display a message count in the menu bar View the messages in any inbox (but especially the watched one) 20Dienstag, 16. April 13 This is what we want to do for our Mac client. We’ve started on a prototype. It’s still very premature, so it doesn’t do much yet.
  • 21. iPhone App Goals View the messages in any inbox Read any message Triage messages by moving to another inbox 21Dienstag, 16. April 13 And this is what we want to do for our iPhone client. (An iPad client would be very similar as well.) This one’s a bit further along, but still pretty rough around the edges. All the data here is loaded from the API and cached locally by the app.
  • 23. Shared Behaviors Showing inboxes and messages Requesting and caching data Showing loading indicators 23Dienstag, 16. April 13 By no coincidence, these are the behaviors implemented by our cross-platform view models. Let’s take a look at the code. (ViewModels, MenubarController?, PopoverController?, TableSources)
  • 25. Let’s get real. 25Dienstag, 16. April 13 Cocoa wasn’t really designed with MVVM in mind. Here are some minor obstacles you may encounter.
  • 26. View Controllers Layout, animations, device rotation, view transitions Seems like view controllers are actually part of the view layer! 26Dienstag, 16. April 13 OS X and iOS both have view (or window) controllers, which can make MVVM confusing at first glance. Once you look deeper, though, it’s not much of a problem at all.
  • 27. View Controllers NSViewController doesn’t do much UIViewController is quite powerful Between views and view controllers, use the easiest one 27Dienstag, 16. April 13 Basically, use the class that will make implementing your view layer easiest. On OS X, you’ll probably just want NSView, since NSViewController is relatively useless. On iOS, you’ll probably want UIViewController, so you can handle rotation, navigation, etc. No matter what you decide to use for your UI, you’ll still have a ViewModel.
  • 28. Data Binding Notifications are too general, and have global scope Key-Value Observing is difficult to use and comes with boilerplate 28Dienstag, 16. April 13 It’s hard to write the indirect relationship from the ViewModel to the View without a powerful system of bindings. Cocoa (and, by extension, Xamarin.Mac and Xamarin.iOS) offers a couple solutions, but they’re woefully inadequate. In addition to these individual problems, neither supports automatic transformation or filtering of bound values. Worse, both are specific to Cocoa, so our V <> VM bindings will look quite different from our VM <> M bindings (which should be cross- platform).
  • 29. Data Binding In Objective-C, we wrote a framework called ReactiveCocoa In C#, we have Reactive Extensions and our ReactiveUI framework 29Dienstag, 16. April 13 Reactive Extensions (or Rx) is an implementation of Functional Reactive Programming, which is unfortunately beyond the scope of this talk, but there are lots of great resources for learning more about it. ReactiveUI is an MVVM framework for .NET. One of its major features is an API for declarative data bindings, built on top of Rx.
  • 30. 30Dienstag, 16. April 13 GitHub for Mac uses ReactiveCocoa to implement MVVM at a large scale. The app itself is written in Objective-C, but the lessons we’ve learned about MVVM are just as applicable to Xamarin.Mac and Xamarin.iOS.
  • 31. Linkage Rx – introtorx.com ReactiveUI – reactiveui.net github:mac – mac.github.com github:windows – windows.github.com 31Dienstag, 16. April 13