Summary: I want to know the best design for creating cross-platform (for example, desktop, web and Silverlight) classes in C # without code duplication, with pluses and minuses of each construction.
I often write new useful classes for a single application domain; there is no reason why they will not work across domains. How can I structure my code to make it perfectly cross-platform?
For example, let's say I wanted to create a generic class "MyTimer" with an interval and an on-tick event. On the desktop, this will use the built-in .NET timer. In Silverlight, I would use DispatchTimer.
Construct # 1 can be "create a class and use preprocessor directives for conditional compilation", for example. "#IF SILVERILGHT ...". However, this makes the code less clear, readable, and maintained.
Construct # 2 can be "create subclasses called DesktopTimer and SilverlightTimer and consume them from MyTimer." How it works?
Although this is a trivial case, I may have more complex classes that, for example, consume platform-specific classes (IsolStorage, DispatchTimer, etc.), but without replacing them directly.
What other constructions / paradigms can be used?
source
share