mvp mix 2015 leveraging mvvm on all platforms
TRANSCRIPT
Who’s this guy… really?
James Montemagno
Developer Evangelist
[email protected] http://motz.codes @JamesMontemagno
Why do we architect our code?
• Organization & Maintainability of Code • Abstract away all business logic • Code re-‐use • Make our views “dumb” and replaceable • Our architect told us to
Model-‐View-‐ViewModel
Model View ViewModel
How to display information
What to display Flow of interaction
Business Logic Data objects
Events
Data Data
Platform Specific Portable
!View Models!
(Properties, Commands, etc.)!!
Models: Data, Services, Etc. Models: Data, Services, Etc.
Why MVVM?
• Organization & Maintainability of Code • Abstract away all business logic • Code re-‐use • Make our views “dumb” and replaceable • Our architect told us to
Model-‐View-‐ViewModel
Model View ViewModel
1 Action
2 Event Handling
3 Command 4 Access Data
5 Notify change
6 Get Changed Data
7 Update UI
Click
Hello!
Magic Binder
Microsoft World
• Built into: – Windows Phone – Windows Store – WPF
• Provides: – Data Binding – Command
• Does NOT Provide – Navigation – IoC – Messaging – Other Fun Stuff
What Did We Just See?
• INotifyPropertyChanged – Notifies UI of Changes – Check value changed
before value changes – Enables Databinding
• ICommand – Contract for “Commanding” – Optional parameters – Can Execute
• Used to enable/disable • Manually must trigger when
property changes
View Services In Action
var av = new UIAlertView( title, message, null, buttonText, null); av.Show();
var builder = new AlertDialog.Builder( ActivityBase.CurrentActivity); builder.SetMessage(message); if (!string.IsNullOrEmpty(title)) { builder.SetTitle(title); } builder.SetPositiveButton( buttonConfirmText, null); return builder;
MessageBox.Show( message, title ?? string.Empty, MessageBoxButton.OK);
Android iOS Windows Phone
To Recap
• MVVM – More maintainable code – More testable code – Ability to abstract platform differences – Just a pattern
• MVVM Framework – Brings in data binding – Speeds up repetitive work
Resources
• MVVM – Awesome Microsoft Docs
• bit.ly/ms-‐mvvm – MVVM Light + Xamarin
• bit.ly/mvvmlight-‐xamarin – Xamarin.Forms + XAML & MVVM
• bit.ly/xamarin-‐forms-‐mvvm – MVVMCross
• https://github.com/MvvmCross/MvvmCross – MVVM Announcement Blog by John Gossman
• http://blogs.msdn.com/b/johngossman/archive/2005/10/08/478683.aspx
Thank you! Q&A
James Montemagno
Developer Evangelist
[email protected] http://motz.codes @JamesMontemagno