How can we avoid changing a lot of code?
- The need for source code changes is bad. Even having to recompile an existing object library is bad. The need for it should be avoided at all cost (how often did you have problems when someone rebuilt the libraries and some things changed?).
- In our little functions and routines we use only a tiny bit of the functionality of the histograms. Usually we just want to create them, fill them, maybe reset them, and store them. This is where a factory comes in.
- We will not directly book the histograms, but we ask the factory to please make a histogram object with the desired properties for us (the “purchase department”). We will get a histogram object which we can fill, reset, store, and so on.
- However, our routines are not aware of the fact that they happen to deal with Hbook histograms today, Root histograms tomorrow, Corba histograms on a server filled by many distributed clients, and who-knows-what in 5 years. The code libraries will happily work with any histogram implementation without recompilation.
- The decision which histograms to use is made outside our functions; there is only one entity in one place (such as the main program) which decides this, and no need to track down all the occurrences of histograms.
- To be very clear: This is only for the “fill” code in your software; if you deal with the histograms interactively, look at them, plot them, fit them, etc, you will need to be aware of the histogram implementation (whether to use PAW or ROOT, for example). But we will shield perhaps 95% of our code from changes of the histogramming package.