building apps with common code for windows 8 and windows phone 8 (wp8)
DESCRIPTION
Windows 8 and WP8 share a lot of commonalities and are heading towards a unified code framework. Still, creating an App that will target both platforms is challenging. In this session we will discuss the commonalities and differences between the platforms, patterns and techniques that will help creating portable code between them.TRANSCRIPT
Tamir DresherSenior Software ArchitectNov 26, 2013
Building Apps with common code for Windows 8 and WP8
About Me
• Software architect, consultant and instructor• Technology addict• .NET and Native Windows Programming• http://www.TamirDresher.com.
One step towards convergence - UX
• Tiles• Touch interface• AppBar • Navigation• Similar XAML
Controls
One step towards convergence - Code
• Common native API – DirectX, WinSock, CRT, STL and more • WinRT - Infrastructure, common type system, standard
programming model. Projected C#, VB, C++ and JavaScript• Shared .NET engine
Life is not perfect
• There are still parts that doesn’t exist in the other platform– System.Threading.Tasks.Parallel, PLINQ etc.– System.Collections.Concurrent namespace
• There are Things that exist but with differences– Dispatcher
• There are things that exist but just don’t work
6
WinRT under different platforms
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff626516(v=vs.105).aspx
NetworkingProximityIn-App PurchaseSensorsLocationFile SystemCore app modelThreading
7
Demo
8
Common Code between platforms
• There are Basically 3 techniques– Link Files– Portable Class Library (PCL)– Dependency Injection
Add as Link
• Using the same file in multiple projects, without copying the file to each project.
• Shared
• Not Shared
10
Add as Link
• Changes in one immediately reflects in the other• Compilation can change due to Conditionals
11
Demo
12
Add as Link – When To Use
• Application logic that is shared but is not portable – each platform has its nuance
• Code that is written in WinRT API. • User controls with no platform dependencies (NOT XAML)– You can use conditional compilation in your code-behind class
Portable Class Library (PCL)
• Portable Class Libraries support a subset of .NET assemblies that target the platforms you choose.
• One code -> one project -> one binary for all platforms• Unsupported in VS2012 Express edition
Portable Class Library (PCL)
• Supports managed code only• Doesn’t use conditional compilation related to platform• Doesn’t use WinRT API• Isn't relevant to UI constructs - XAML code isn’t portable
15
16
Demo
17
Portable Class Library – When To Use
• Shared Managed Code that deals with Logic• Code that doesn’t depends on specific platform API
18
How To Deal with Non-Portable Code
• Using the Adapter Pattern
PCL
ISomeService
Win8WP8
ServiceAdapterWin8ServiceAdapterWP8
3rdPartyWP8 3rdPartyWin8
19
Sharing UI Code
• Separate UI from app logic
20
Summary
• Separate UI from app logic• Share your logic in PCL • Use Linked Files when necessary (WinRT)• Abstract your dependencies and use DI• We are on the path for convergence but there is still a long way
to go
Presenter contact detailsc: +972-52-4772946e: [email protected]: TamirDresher.comw: www.codevalue.net