three's company - writing for the desktop, browser, and phone
DESCRIPTION
Presented to Akron AITP on 5/21/2013TRANSCRIPT
Tips & Tricks for Targeting Multiple Platforms with Portable Code
Presented by Sarah Dutkiewicz, Cleveland Tech Consulting
Scenarios
Tips & tricks for general multiple platform development
Overview of Portable Class Library in .NET
Experiences that cross from one device/platform to another
Microsoft Account
Office
SkyDrive
Xbox SmartGlass
Formerly known as a Windows Live ID
Combination of email address and password
Unified login for Microsoft tools and other apps that ask for a Microsoft account
Xbox LIVE
Outlook.com
SkyDrive
Windows Phone
Skype
Data storage in the cloud
Office in the browser – including Word, Excel, PowerPoint, and OneNote
Supported platforms include: Windows 8 (built-in)
Windows Vista and later
Mac OS X
Mobile
Windows Phone
iPhone / iPad
Android
Found for Mac
iAnnotate for iPad and Android
SoundGecko for iPhone, Android, and Windows Phone
Genius Scan+ for iPhone, iPad
Remarks for iPad
DocScan for iPhone and iPad
How to Develop For Multiple Devices/Platforms
The better understanding of your audience, the better understanding of which platforms to target.
The better understanding of which platforms to target, the better view of what features are available as an overall view and platform-specific
Be sure you understand what it is you are building and what platform(s) you are targeting.
Write the code once and reuse it, rather than writing the code in multiple places and then realizing it can be isolated into one library.
Media – images, video
Design aspects
Models
View Models
Consumed APIs/RESTful services
Web & Windows Phone – Perhaps HTML5, Silverlight, or C#
Web, Windows Phone, and Windows Store – C#
Web & general mobile – consider HTML5
User Interface
Business Logic
Data Layer
Some code is shareable without the portable class library
Share the code that would be the same on each platform
Typically not the UI
Mostly as much business logic as possible
Perhaps data layer
Portable view models
Validation
Use design patterns that lend themselves to reusability
Model-View-ViewModel (MVVM)
Model-View-Controller (MVC)
Use third party tools that support cross-platform development
Appcelerator
PhoneGap
RhoMobile
WidgetPad
MoSync
Visual Studio for targeting Windows
MonoGame to help target many platforms:
iOS
Android
Mac OS X
Linux
Windows 8 Metro
Futures include:
Windows Phone 8
OUYA (Android-based gaming station)
PlayStation Mobile
A look at Portable Class Libraries
Desktop
Web
Phone
Cloud
Xbox
Tablets
.NET 4 and Silverlight 4
Portable Library Tools for Visual Studio 2010
Built-in Portable Library support in Visual Studio 2012
.NET Framework 4, Update 4.0.3 for the .NET Framework 4, and .NET Framework 4.5
.NET for Windows store apps
Windows Phone 7 and higher (Windows Phone SDK 8.0 for Windows Phone 8 support)
Silverlight 4 and 5
Xbox 360
They must be shared across the target platforms you selected.
They must behave similarly across those platforms.
They must not be candidates for deprecation.
They must make sense in a portable environment, especially when supporting members are not portable.
Portable Class Library support appears under Version Information for a MSDN article
Include shared business logic and data layer logic in the portable class libraries
Use MVVM to write the apps
Models and View Models can be shared across platforms and included in portable libraries
Platform-specific views
Portable abstractions for non-portable functionality
Implement the abstractions for each platform
Use IoC or service locator to hook up implementations
• How to display information
• Written in XAML, HTML, some other markup language
• Platform-specificView
• What information to display
• Flow of interaction
• Can be shared in a portable class libraryView Model
• Data objects
• Business logic
• Can be shared in a portable class libraryModel
Portable Class Library
(Models & View Models)
Windows Store App
(Views)
Windows Phone App
(Views)
Silverlight (Views)
Calling Non-Portable Members from a Portable Class
Cannot call the non-portables directly
Need to create an abstract class in the Portable Class Library project and use that class from all portable code
HelpDesk Application
Metro Style App
Windows Phone 7 App
Download Source Code
Store common logic in the portable class library
Business logic, but not UI
Use abstract classes to work with non-portable code
For example, this may be applied to the data layer.
Use the MVVM pattern to help minimize code.
MVVM MVVM Light Toolkit (portable fork)
MvvmCross
IoC Autofac
PortableIoC
Ninject (portable fork)
Microsoft.Composition
Others Json.NET
Metrolog
Zlib.Portable
Portable PRISM
Write Portable Code
Visual Studio Toolbox: Portable Class Libraries
Portable Class Libraries Contrib
Build 2012: Create Cross-platform Apps using Portable Class Libraries
.NET 4.5: David Kean and Mircea Trofin – Portable Libraries
Coding4Fun: Portable is as portable does… Maximizing code reuse via the magic of the Portable Class Library
Coding4Fun: Digging into your code with the free Microsoft Code Digger and the power of Pex
CodeProject: MonoGame Goes Portable
How to Make Portable Class Libraries Work for You
Example: Disentanglement by Daniel Plaisted
Portable Class Libraries and other portable libraries make it easy to develop for multiple platforms.
Know the lay of the land.
Know your audience.
Know your goals for your app.
Keep your commonalities together.
Develop accordingly.