Hi,
This is my first post to javaranch so go easy on me.
I've been coding C++ now for around 7 years, but also doing bits and pieces of
Java here and there, hoping to get enough experience to make the leap over to Java fully someday.
Anyway, onto my question - The company that I am currently contracting for make extensive use of multiple inheritence and although I have personally avoided this in the past, I can now see, that with care it can work really really well.
Some of our most heavily used classes are often inherited multiply as what you might call 'mix-ins'. I know that in Java you can use interfaces to achieve similar results to Multiple Inheritence (although without implementation in the interface of course) and that you could also use other alternatives such as aggregation and delegation. But in certain circumstances I just can't see anything nearly as intuitive as multiple inheritence.
I'll give a quick example of one that I was just having a discussion with a collegue about. It's not the best example - as it's fairly simple, but it's the easiest for me to explain here.
A lot of the objects in our system provide statistics to a central controller that sits on the network monitoring the server farm. There is a central Singleton StatisticsManager object along with other objects that are used for transport of data etc. Objects provide statistics by inheriting from the
StatableObject interface which contains a small amount of functions - the main one being
SetStatistic. Objects call this SetStatistics method when they want to update a particular statistic. How would you implement a similar system in Java, I couldn't think of anything nearly as intuitive.
I suppose one method would be just call the StatisticsManager directly in the class when the stat changes, but this would require knowledge of the StatisticsManager and would mean I would have to send class name and other information that doesn't change with each call rather than just passing it to the StatableObject constructor.
Any thoughts would be much appreciated, could do with some ammunition for my regular C++ vs Java arguments that I seem to be seeing more and more now ;-)
Regards,
Steve