Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Tips and Tricks

Hi Jeremy,

Here's one little example that I've found to be useful in explaining the
value of intertype declarations.

Suppose you have a hierarchy of classes with Employee at the base, and
derived from it are Manager, MemberTechnicalStaff, and Director. Suppose
further that the Employee class has dozens of methods and many fields.
Even though all of these fields and methods belong to the Employee class
and its subclasses there can be multiple concerns present. For example,
payroll is one concern that might have four methods and two data members,
and that the derived classes need to access these data members (through
protected accessors). When there's a bug in the payroll code, we
unfortunately have to look further than the four payroll methods
themselves: we have to look at *all* of the methods that belong to the
class. We need to look at all of the methods because it's possible some
other Employee method accessed the payroll data when it shouldn't have.
While it's nice to know in object-oriented programming that no other
classes can access these members Java still requires discipline *within*
the Employee classes.

You can achieve finer granularity of access to data by using intertype
declarations, which solves this problem elegantly. You can write a Payroll
aspect that contains intertype declarations for the payroll methods and
data for each class. Now, here's the kicker: The data members can be
aspect private. An aspect private data member is accessibly only by the
code in the aspect itself -- not even the methods of the Employee class or
its subclasses can access it. So, aspect private data not only gives you
better control in cases like this, it is also useful for debugging: by
just seeing the Payroll aspect you can know that the data is private, and
that this invariant will hold. That will make it much easier to track down
any bugs.

Once you start thinking of members with this kind of granularity, you'll
probably find you can't live without it!

-Macneil


On Fri, 31 Oct 2003, Jeremy E. Denton wrote:

>
> Hey,
>
> I've just recently stumbled across Aspect Oriented Programming and it's
> piqued my curiousity but I am finding the learning curve is a bit steep
> learning it on my own from just the content provided on the net. It
> certainly adds a significant level of complexity to Java. Does anyone have
> any suggestions on how best to approach it? What metaphors, tricks or ways
> of thinking that aptly describe it?
>
> I noticed that some of the documentation that comes with AspectJ, uses a
> figure example. lines, points etc. I've gotten the impression that Aspect
> orient programming can help in the development of graphics applications. I'd
> be curious to understand how this might specificly apply.
>
> Jeremy E. Denton
> software developer
> galdos systems inc
> Opinions, conclusions, recommendations, and other information presented in
> this message are not given or necessarily endorsed by my employer or firm.
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>



Back to the top