Here's an article from Sys-con that details the implementation of a solution using dynamic proxies. http://www.sys-con.com/story/?storyid=37748&DE=1 It will provide you with a very good starting point to look at for creating your own implementation. I've used similar solutions to address various problems. There will be some overhead associated with the dynamic proxy. The best advice I can give is to implement a POC and then make your own judgment call after analyzing your test results.
Michael Butler -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christopher L Merrill Sent: Monday, March 28, 2005 1:36 PM To: Research Triangle Java User's Group mailing list. Subject: [Juglist] multiple inheritance and/or a better aggregation method? I'm looking for a technique or pattern to solve the following problem: I have a class (TheClass) which needs to implement multiple interfaces (iA, iB and iC). Each has a default implementation which is sufficient for my needs (AImpl, BImpl and CImpl). In C++, you would use multiple inheritance to solve this problem - inheriting from all three default implementations in order to inherit all the default behavior. Of course, this is not possible in Java (and frankly, I don't miss the complexity of multiple inheritance). In the past, I simply implement the interface and pass on method calls to an aggregated class (e.g. AImpl). It's simple, but ugly. I think this could be done with a dynamic proxy, but I'm concerned about the performance of the heavy use of reflection. Some parts of our application are extremely performance-sensitive. In my case, it is a compile-time problem -- no run-time variability is required (in terms of the interfaces implemented). So using reflection to direct every method call seems like overkill. From a language standpoint, it seems to me that some way of combining the "implements" clause with a contained (aggregated) member would be the ideal way to solve the problem. I think of it as "hyper-aggregation". For example: class TheClass implements iA, iB, iC { AImpl _myvarA provides iA = new AImpl(); AImpl _myvarB provides iB = new BImpl(); AImpl _myvarC provides iV = new CImpl(); } Thus, the interface iA of AImpl would be exposed as the implementation of iA for TheClass. Ideally, one would be able to override the implementations of each interface within TheClass, when required. In essence, it is an automatic usage of a dynamic proxy implemented by the compiler. The method-call forwarding would be decided by the compiler, rather than run-time reflection. Assuming that I am not the first person to run into the problem (nor the brightest), I have to ask how others solve this problem? Is there some obvious problems with my solution above that has kept something like this from being added to Java? I can't be the first person to have thought of it. TIA, C -- ------------------------------------------------------------------------- Chris Merrill | http://www.webperformanceinc.com Web Performance Inc. Website Load Testing and Stress Testing Software ------------------------------------------------------------------------- _______________________________________________ Juglist mailing list [email protected] http://trijug.org/mailman/listinfo/juglist_trijug.org _______________________________________________ Juglist mailing list [email protected] http://trijug.org/mailman/listinfo/juglist_trijug.org
