Building apps with common code for windows 8 and windows phone 8 (WP8)
-
Upload
tamir-dresher -
Category
Technology
-
view
280 -
download
1
description
Transcript of Building apps with common code for windows 8 and windows phone 8 (WP8)
![Page 1: Building apps with common code for windows 8 and windows phone 8 (WP8)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/1.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/2.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/3.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/4.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/5.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/6.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/7.jpg)
7
Demo
![Page 8: Building apps with common code for windows 8 and windows phone 8 (WP8)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/8.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/9.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/10.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/11.jpg)
11
Demo
![Page 12: Building apps with common code for windows 8 and windows phone 8 (WP8)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/12.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/13.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/14.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/15.jpg)
15
![Page 16: Building apps with common code for windows 8 and windows phone 8 (WP8)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/16.jpg)
16
Demo
![Page 17: Building apps with common code for windows 8 and windows phone 8 (WP8)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/17.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/18.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/19.jpg)
19
Sharing UI Code
• Separate UI from app logic
![Page 20: Building apps with common code for windows 8 and windows phone 8 (WP8)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/20.jpg)
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)](https://reader036.fdocuments.in/reader036/viewer/2022062616/54b4ede14a79590a688b461a/html5/thumbnails/21.jpg)
Presenter contact detailsc: +972-52-4772946e: [email protected]: TamirDresher.comw: www.codevalue.net