Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Can inter-type declarations do this?

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



Back to the top