Today we have a several type of devices and the number is growing. So, we have to develop our application several times. A way to add functionality to our applications without difficult is to use a derivation of the Abstract Design Pattern : Template Method. In this tutorial we learn how to add functionality to several applications and make them use the same Architecture but details vary depending on the context. Our contexts are Windows Phone, Surface and XBOX data displaying behaviors We will use a Portable class Library that hold the shared functionnalities.
- Add a new file
- choose Portable class Library
- Click OK
- Check the targeted framworks and click OK
- Create a ScreenBase Class as follow
- Create a PhoneScreenService class as follow
GetData, FormatData and RenderContent are protected because TabletScreenService, PhoneScreenService will be use as base classes
- Create a TabletScreenService class as follow
- To test it create a console application and référence our Portable Class Library as follow.
- Press F5 to run application, so you can see that the behaviour is different between windows Phone and Surface tablet.Our sample is finish but in a real world application, we must reference our portable class library in both windows Phone client, surface client, XBOX client and sower. and implement business logic for each client,