Three's Company - Writing for the Desktop, Browser, and Phone
Tips & Tricks for Targeting Multiple Platforms with Portable CodePresented by Sarah Dutkiewicz, Cleveland Tech Consultingsarah@cletechconsulting.com
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
The better understanding of your audience,the better understanding of which platformsto target. The better understanding of which platformsto target, the better view of what features areavailable as an overall view and platform-specific
Be sure you understand what it isyou are building and whatplatform(s) you are targeting. Write the code once and reuse it,rather than writing the code inmultiple places and then realizing itcan be isolated into one library.
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
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
.NET 4 and Silverlight 4 Portable Library Tools for Visual Studio2010 Built-in Portable Library support in VisualStudio 2012
.NET Framework 4, Update 4.0.3 for the.NET Framework 4, and .NET Framework4.5 .NET for Windows store apps Windows Phone 7 and higher (WindowsPhone SDK 8.0 for Windows Phone 8support) Silverlight 4 and 5 Xbox 360
They must be shared across the target platforms youselected. 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 notportable. Portable Class Library support appears underVersion 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 portablelibraries 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
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 classfrom 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.
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 thePortable Class Library Coding4Fun: Digging into your code with the free Microsoft Code Digger and thepower of Pex CodeProject: MonoGame Goes Portable How to Make Portable Class Libraries Work forYou Example: Disentanglement by Daniel Plaisted
Portable Class Libraries and other portable libraries make it easy to develop formultiple platforms. Know the lay of the land. Know your audience. Know your goals for your app. Keep your commonalities together. Develop accordingly.