Hi Neale Thanks for the reply and the useful info. I'll give what you suggested a try.
One thing I should point out though is that Fish and Mammal are both concrete classes, not interfaces as your example suggests. Do you think that will cause a problem? To make things even more interesting, and this is where my simplified example starts to break down, Fish actually extends Mammal too (!). It's actually more like this in real life: Current Situation ---------------------- 1) OrderClass <----------- AbstractWorkflowClass <------------------------------------------- DomainClass 2) InvoiceClass <--------------------------------------------- DomainWithExtraStuffClass <-- DomainClass I need to modify InvoiceClass so it also extends AbstractWorkFlowClass, and make AbstractWorkflowClass extend DomainWithExtraStuffClass *but only* when dealing with InvoiceClass instances. When I'm dealing with OrderClass, AbstractWorkflowClass should still extend the base DomainClass. New Situation ------------------ 1) OrderClass <----------- AbstractWorkflowClass <--------------------------------------------------- DomainClass 2) InvoiceClass <--------- AbstractWorkflowClass <------- DomainWithExtraStuffClass <----- DomainClass Which obviously isn't normally possible in Java, which is why I thought an ITD might be the way forward. Incidentally, I was hoping I could change AbstractWorkflowClass to extend DomainWithExtraStuffClass but apparently (and I can understand the concerns) we can't do this because it would mean making all the functionality in DomainWithExtraStuffClass available to OrderClass (and the many other classes that extend it - it's a big system) You've given me something to go on and it sounds promising, so thanks again for the assistance. Richard From: Neale Upstone Sent: Thursday, October 14, 2010 9:38 PM To: aspectj-users@eclipse.org Subject: Re: [aspectj-users] Can inter-type declarations do this? It sounds like what you want is to have Dog extend AbstractCreature, Mammal, and Shark extend AbstractCreature,Fish In the world of ITDs I think what you're looking to do is to have the abstractness of AbtractCreature fulfilled by either Mammal or Fish. YOu should be able to do: class Dog extends AbstractCreature implements Mammal { } And then declare the implementations for the abstract methods in AbstractCreature as ITDs in both Mammal and Fish: something like: public aspect MammalImpl { public void Mammal.methodThatsAbstractInAbstractCreature() { //method impl; } } On 14/10/2010 17:08, Richard Gundersen wrote: Hi I'm struggling with a problem that I *think* AspectJ might be able to help me with, but I'm not sure so I was hoping someone could give me some advice. I want to be able to change the class that a certain class' superclass extends, if that makes sense? So (in terms that I understand) I might have Dog, which extends AbstractCreature, which in turn extends Mammal. However alongside Dog, I now want to add 'Shark' which I still want to extend AbstractCreature (because it has some useful functionality). But, this time, I want to change the class that AbstractCreature extends to 'Fish', rather than Mammal. Like this: Dog <-- AbstractCreature <-- Mammal Shark <-- AbstractCreature <-- Fish So basically if AbstractCreature is being subclasses by a dog, it should extend Mannal, or if by Shark, it should extend Fish. I'm hoping there's a magical inter-type declaration annotation (or even better a Spring/AspectJ annotation, something like @DeclareParents perhaps) that I can add to both Dog and Shark. I would really appreciate any help anyone can give me on this. My real world example is some really complex code that I don't want to duplicate/mess with too much, so AOP would seem to be a perfect solution. If its of any use, in my real world example, Shark extends Fish directly, but I need to modify it so Shark now extends AbstractCreature, and then (ultimately) Fish, not Mammal. Thanks Richard _______________________________________________ aspectj-users mailing list aspectj-users@eclipse.org https://dev.eclipse.org/mailman/listinfo/aspectj-users -------------------------------------------------------------------------------- _______________________________________________ aspectj-users mailing list aspectj-users@eclipse.org https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________ aspectj-users mailing list aspectj-users@eclipse.org https://dev.eclipse.org/mailman/listinfo/aspectj-users