Reputation: 4696
Suppose I needed to develop a wrapper assembly that allows the use of any one of several underlying frameworks. The latter could be for data access, graphics, or whatever. This is assuming that all of the underlying libraries offer essentially the same functionality but, for whatever reason, you may have to use one or the other of them in different circumstances.
The caller would wish to code to a single specification and swap in whichever underlying framework was to be used, without making source changes.
What language and framework features in C# and .NET can best avoid maintaining multiple copies of the wrapper class library, since that redundancy would result in the need to make multiple updates for fixes and enhancements to the wrapper API? C# interfaces and delegates are two features that come to mind.
Upvotes: 2
Views: 272
Reputation: 245419
You would create the outline for the wrapper using Interfaces.
You would then implement those interfaces for each wrapper which uses the specific underlying frameworks.
The individual wrappers could then easily be swapped in and out for each other without having to change the calling code.
Depending on your needs, you could also using configuration values to dynamically instantiate a given wrapper at runtime. This would allow you to swap the wrappers without needing to recompile your code.
Upvotes: 4