Partial classes vs. plugin architecture for extensibility
Extensibility is the ability to extend an existing system with modifications or additional features. I have been working on a project that allows users to create custom reports using a set of tokens (like tags in HTML to create a page). We have different sets of tokens for different features and in the future want to be able to sell different versions that are differentiated by the token sets provided. The problem is that there are too many tokens and the way the component has been written the main control knows about all of them.
Clearly, the current monolithic design approach must be discarded. Because we are using C# and .Net there are two possible solutions: use partial classes and conditional compilation to generate different versions or implement a plug-in architecture where plug-ins are used to implement sets of tokens.
Since the project is implemented in .Net 1.1, the only possible solution was the plug-in architecture. But looking at the existing code and the technology we are working with (ASP.Net) it will be very difficult to design clean interfaces for the plug-ins to use. There are a lot of token sets that will depends on things like the Controls collection, ASP.net page, and other ASP.Net infrastructure.
The partial class option is only available with the advent of .Net 2.0 and provides a better alternative for the type of extensibility we are looking for. We should be able to implement specific token sets as a partial class which will have access to our ASP.Net control. I find this a satisfactory solution because creating a plug-in architecture would open up a whole can of worms with security, reflection, and performance.
The only downside is that we’re relying on a new platform feature which forces all our uses to upgrade. This shouldn’t be a problem because the project will run in a server environment.
Update: As a follow up to my previous post, I now realize that partial classes are not the way to go. In essence partial classes allow a reorganization of the code for a class but what I really need are seperate classes to represent the sets of tokens.