Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
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@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/aspectj-users

Back to the top