-
1. Re: Duplicate method names in mixins
kabirkhan Jan 6, 2005 4:20 AM (in response to john.howard9)Hi,
the method names would need to be different. The mixin methods get compiled into the main class, so for the examples you show you would end up with something like:public HelloWorld implements Test, Test1 { //Original HelloWorld code //Added during instrumentation Test test = new HelloWorldImpl(this); Test1 test1 = new HelloWorldImpl1(this); public String getWorldName() { return test.getWorldName(); } public String getWorldName() { return test1.getWorldName(); } }
So you end up with two methods with the same signature, which is not allowed. This is similar to if in "normal" java you wanted to implement two interfaces with the same method names; you would only implement one "copy" of the method.
Kabir -
2. Re: Duplicate method names in mixins
kabirkhan Jan 6, 2005 4:22 AM (in response to john.howard9)It should be possible to create a mixin that implements BOTH interfaces though
-
3. Re: Duplicate method names in mixins
john.howard9 Jan 6, 2005 1:47 PM (in response to john.howard9)Hi Kabir,
Thanks for the reply, now I understand the implementation I understand the problem. Does make it kind of restrictive for AOP though, perhaps Java should be extended to support multiple inheritance of this type. I saw some discussion on a Java forum suggesting that calls could be namespaced using the interface that they represent e.g.public String Test.getWorldName() { return test.getWorldName(); } public String Test1.getWorldName() { return test1.getWorldName(); }
Seemed a neat solution.
John. -
4. Re: Duplicate method names in mixins
bill.burke Jan 6, 2005 2:09 PM (in response to john.howard9)You don't want multi-inheritance in Java. Then you have to worry about a lot of things like how classes are initialized and such. The virtual vs. non-virtual decision that C++ has.
We made the decision in JBoss AOP to have non-virtual inheritance. -
5. Re: Duplicate method names in mixins
john.howard9 Jan 6, 2005 2:43 PM (in response to john.howard9)I remember C++ multiple inheritance well, since converting to Java, Coplien's purple book sits quietly gathering dust on a shelf.
On the project I was working on I had been using IAdaptable to extend basic java classes so that I could use them in a tree view and a graphical view. As a first look at AOP I thought I could improve on this via an introduction and a mixin. I still have two mixin classes one for the tree view and one for the graphical view, so from my code's point of view there is no multiple inheritance and I have no desire to go back there. I don't really know if this is an appropriate use of AOP, maybe not, but it does work well and simplifies the code. If it is appropriate the maybe AOP should support it in some way, in my case I could change the method signatures, but that won't always be the case.
Just wondered if what I am doing is sensible?
Thanks,
John.