Mit dem Release von Windows Phone 8 und Windows 8 setzen die beiden Betriebssysteme zum ersten Mal auf den gleichen Kernel auf. Für Entwickler stellt sich hier natürlich die Frage: Wie einfach ist es mit einmaligem Programmieraufwand beide Plattformen zu bedienen? Dieses Session stellt Euch Strategien vor, die Ihr nutzen könnt um Eure Arbeit nicht zweimal machen zu müssen und arbeitet die Stellen heraus, an denen es sinnvoll ist, dennoch zweimal den Code anzufassen.
Scaling API-first – The story of a global engineering organization
Windows und Windows Phone App Entwicklung (Daniel Meixner, DWX 2014)
1. Windows und
Windows Phone App Entwicklung
Daniel Meixner
Technical Evangelist
Microsoft Deutschland
@DanielMeixner
DevelopersDevelopersDevelopersDevelopers.Net
11. You can adapt one design across devices
User Interface App Model Tools StoreAPIs
12. You can tailor the design to each device
User Interface App Model Tools StoreAPIs
13. 13
80% exact same XAML 20% custom
Common SignatureOptimized
DatePicker
TimePicker
CommandBar
AppBar
Button
CheckBox
RadioButton ProgressBar
Slider
ToggleSwitch
Hub
Pivot
ListView
GridView
User Interface App Model Tools StoreAPIs
14. App Model APIs
Develop your app in a way that’s familiar
User Interface Tools Store
HTML / CSS
JavaScript
Windows Runtime
C# / VB
Windows Kernel Services
C / C++
XAML DirectX
15. The Windows Runtime (WinRT) is the
shared runtime and API space used by
store apps across the Windows platform
(phone and client)
Dramatic convergence in 8.1
• Goal is 100% convergence for dev scenarios
• In 8.0, we had ~30% API convergence
• With 8.1, we move well past 90%+ convergence
App Model APIsUser Interface Tools Store
21. Overall Strategy
Embrace & separate
differences
Separate View
(MVVM)
Separate
platform
specific calls
(Libs)
Try to share everything
else
Let‘s see...
24. Shared Code: File-Level (Add as Link)
• App logic common to both apps, but not
portable
• Code containing Windows Runtime API calls
• Share outside of Universal Apps
25. Shared Code: Classpart-Level
(Partial Classes)
public partial class MyClass
{
public void CommonMethodA()
{
// code that is common
}
public int CommonMethodB()
{
int result = 0;
// code that is common
return result;
}
}
public partial class MyClass
{
public void PlatformSpecificMethod()
{
// specific code for platform Á
}
}
}
public partial class MyClass
{
public void PlatformSpecificMethod()
{
// specific code for platform B
}
}
26. Shared Code: Line Level (Conditional Compilation)
public class MyClass
{
public void CommonMethodA()
{
// code that is common to Windows Phone 8 and Windows 8
}
public int CommonMethodB()
{
int result = 0;
// code that is common to Windows Phone 8 and Windows 8
return result;
}
public void PlatformSpecificMethod()
{
#if WINDOWS_APP
// code for W8.1
#else
// …
#endif
}
}
27. public class MyWin8Class : MyBaseClass
{
public override void PlatformSpecificMethod()
{
// Implement this method specific to Win 8
}
} }
Patterns: Abstract Base Class
public abstract class MyBaseClass
{
public void CommonMethodA()
{
// code that is common
}
public int CommonMethodB()
{
int result = 0;
// code that is common
return result;
}
public abstract void PlatformSpecificMethod();
}
Add as Link /
Shared Folder
Portable Class Library
public class MyWP8Class : MyBaseClass
{
public override void PlatformSpecificMethod()
{
// Implement this method specific to WP8
}
}
28. public class MyClass
{
private IPlatformSpecificCode _platformImpl;
public MyClass(IPlatformSpecificCode platformImpl)
{
_platformImpl = platformImpl;
}
public void CommonMethodA()
{ ... }
public int CommonMethodB()
{ ... }
public void PlatformSpecificMethod()
{
_platformImpl.PlatformSpecificMethodImpl();
}
}
public interface IPlatformSpecificCode
{
void PlatformSpecificMethodImpl();
}
// Windows 8 app project
public class MyWin8Implementation : IPlatformSpecificCode
{
public void PlatformSpecificMethod()
{
// Implemented for Windows 8
}
}
Patterns: Interfaces & DI
// Windows Phone app project
public class MyWinPhone 8Implementation : IPlatformSpecificCode
{
public void PlatformSpecificMethod()
{
// Implemented for Windows Phone 8
}
}
33. Share what you can share.
Don‘t share what you can‘t share.
34. What do you want to share today?
Microsoft
Azure
Store Registration, Purchasing
Push Notifications …
Universal App Sync
Universal App
Visual Studio
35. Summary
Building for both WP8.1 & WP8.1 is easy
Universal Apps are flexible
Alernative ways to share code exist
More to come … stay tuned!