building apps with common code for windows 8 and windows phone 8 (wp8)

21
Tamir Dresher Senior Software Architect Nov 26, 2013 Building Apps with common code for Windows 8 and WP8

Upload: tamir-dresher

Post on 13-Jan-2015

280 views

Category:

Technology


1 download

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

Page 1: Building apps with common code for windows 8 and windows phone 8 (WP8)

Tamir DresherSenior Software ArchitectNov 26, 2013

Building Apps with common code for Windows 8 and WP8

Page 2: Building apps with common code for windows 8 and windows phone 8 (WP8)

About Me

• Software architect, consultant and instructor• Technology addict• .NET and Native Windows Programming• http://www.TamirDresher.com.

Page 3: Building apps with common code for windows 8 and windows phone 8 (WP8)

One step towards convergence - UX

• Tiles• Touch interface• AppBar • Navigation• Similar XAML

Controls

Page 4: Building apps with common code for windows 8 and windows phone 8 (WP8)

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

Page 5: Building apps with common code for windows 8 and windows phone 8 (WP8)

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

Page 6: Building apps with common code for windows 8 and windows phone 8 (WP8)

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

Page 7: Building apps with common code for windows 8 and windows phone 8 (WP8)

7

Demo

Page 8: Building apps with common code for windows 8 and windows phone 8 (WP8)

8

Common Code between platforms

• There are Basically 3 techniques– Link Files– Portable Class Library (PCL)– Dependency Injection

Page 9: Building apps with common code for windows 8 and windows phone 8 (WP8)

Add as Link

• Using the same file in multiple projects, without copying the file to each project.

• Shared 

• Not Shared 

Page 10: Building apps with common code for windows 8 and windows phone 8 (WP8)

10

Add as Link

• Changes in one immediately reflects in the other• Compilation can change due to Conditionals

Page 11: Building apps with common code for windows 8 and windows phone 8 (WP8)

11

Demo

Page 12: Building apps with common code for windows 8 and windows phone 8 (WP8)

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

Page 13: Building apps with common code for windows 8 and windows phone 8 (WP8)

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

Page 14: Building apps with common code for windows 8 and windows phone 8 (WP8)

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

Page 15: Building apps with common code for windows 8 and windows phone 8 (WP8)

15

Page 16: Building apps with common code for windows 8 and windows phone 8 (WP8)

16

Demo

Page 17: Building apps with common code for windows 8 and windows phone 8 (WP8)

17

Portable Class Library – When To Use

• Shared Managed Code that deals with Logic• Code that doesn’t depends on specific platform API

Page 18: Building apps with common code for windows 8 and windows phone 8 (WP8)

18

How To Deal with Non-Portable Code

• Using the Adapter Pattern

PCL

ISomeService

Win8WP8

ServiceAdapterWin8ServiceAdapterWP8

3rdPartyWP8 3rdPartyWin8

Page 19: Building apps with common code for windows 8 and windows phone 8 (WP8)

19

Sharing UI Code

• Separate UI from app logic

Page 20: Building apps with common code for windows 8 and windows phone 8 (WP8)

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

Page 21: Building apps with common code for windows 8 and windows phone 8 (WP8)

Presenter contact detailsc: +972-52-4772946e: [email protected]: TamirDresher.comw: www.codevalue.net