I’m currently writing a charting application. I am using Zedgraph to display 2D plots. Within my application I need to display approx 8 different types of charts, and each one needs to provide slightly different functionality.
The issue here, is sometimes I have some “base ” functionality that most classes will use, sometimes I have “added” functionality that some classes will use and other times its a mix-mash of these. On top of this, the data displayed in the charts is again disjoint, and the visual appearance is also disjoint.
Consider the following functionality that may apply to one or more charts:
- Ability for the chart to automatically scroll (with live data)
- Ability for the chart to zoom in the horizontal direction
- Ability for the chart to zoom in the vertical direction
- Ability for the user to edit points in the chart
- Ability for the user to select a region of data
- Ability for the user to change the scales of the chart
- Ability for the chart to “zoom to fit”
- Ability to ahve one,two,three or four vertical axes
- Ability to show a chart overlay
- etc
Bringing this all together, some functionality applies to all charts, some applies to a subset of charts, and some applies to individual charts. Currently I can see no hierarchy of functionality to implement.
My current implementation uses a base class (to provide global functionality that I can clearly see) and then I have two ‘forks’ off this base class, but I’m now stuck at how to implement the disjoint functionality over individual classes. I can’t use an abstract class, as sometimes I need to inherit from multiple classes, but I don’t want to provide an interface, as the code is exactly the same.
So, what do I do here? Do I maybe use extension methods to enable specific functionality?
Given that you have so many aspects of functionality, that they they seem rather independent (any particular chart could have any sub-set of the features, or close to it), and that it would seem to me that these are the types of things that may change over time with the application, you would want to spend some up front time generalizing this rather than implementing them on a per-chart basis.
I would simply make a general purpose “Chart” user control and implement all of the features. Then, for each feature, give it a boolean property to enable/disable it. (i.e.
IsHorizontalScrollable,IsVerticalScrollable,IsSelectionEnabled,ArePointsEditable) Then each actual instance of the form just needs to set the appropriate properties of your more general form along with the actual data for it.