Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Thoughts about an AspectJ classloader

> Also, although I'm willing to use introduction in it's current form,
> it does strike me as having a slightly bad smell in that it (arguably)
> breaks encapsulation. I think that having sub -interfaces or -classes
> that contain the introductions might be a cleaner approach.

In my experience introductions actually help preserve encapsulation. For
example, let's say you have classes Base1, Derived1, and Derived2 and you
want to add a concern C that affects B1, D1, and D2. If concern C requires
data-members you are stuck with protected data (or at least protected
accessors to that data) which means that *all* of the D1 and D2 methods
have access to it. This can cause problems down the line when concern C is
changed yet it's not obvious what methods in D1 and D2 affected it.

This problem is avoided by using private intertype declarations. Concern C
is introduced to the classes, but those classes can't access the internals
of C. By just looking at the code you can be assured of this property.

In some ways I find the discussion similar to friends in C++, though I
would hesistate to make such an association.

-Macneil



Back to the top