Skip to main content

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

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.

Briefly: the best way is to start from first principles
(and avoid the snare of the quick fix...)

You should be able to understand AOP and write your own aspects
after reading the AspectJ programming guide and examples, if you
have a grasp of OO programming with Java.  (By contrast, a lot
of what's on the net are confusing attempts to sell something
else as AOP.)

Here's what the AspectJ docs recommend:

  To learn the AspectJ language, read the Programming Guide,
  keeping the Semantics appendix  nearby as the best reference
  for AspectJ usage. Focus initially on the join point model
  and pointcuts, concepts AOP adds to OOP. To read about how
  the examples work, see the Examples  section in the
  Programming Guide. View and navigate the crosscutting
  structure using the ajbrowser structure viewer, as described
  in the AspectJ Browser section of the Development
  Environment Guide.

  To start using AspectJ with your own code, modify the example
  aspects to apply to your classes. [...]

Here's why we recommend it, for AspectJ and AOP.  (Below are
some new materials and a list of relevant publications.)

The AspectJ programming guide has been evolved over 2-3 years
by the developers of AOP/AspectJ with feedback from the user
community.  The guide works because it focuses on the key point:
AOP aims to modularize crosscutting concerns, and AspectJ
aims to bring AOP to Java.  Everything else derives from that.
Once you understand the problem, you can see how various
features form part of a solution and begin to appreciate
the code for an aspect that puts it all together to address
a particular crosscutting concern.

The IDE support - in AJBrowser and AJDT for Eclipse - does
make it easier to edit and compile AspectJ programs, but
its main purpose is to help people concretely understand the
crosscutting concern by letting them see and navigate the
crosscutting structure.  That makes it tangible and helps
you see it in other programs that haven't been written
with AspectJ.  Regardless of whether you use AspectJ
(or anything else) to do AOP, it helps to have a mental lens
and tool support for picking out crosscutting concerns, so
you can manage around them.

The AspectJ examples were designed not only to demonstrate
AspectJ features, but mainly to show how designs can look
when crosscutting concerns can be modularized.  E.g.,
the ability of a Java class to work as a JavaBean if it
complies with certain structural rules can be encapsulated
in an aspect.  While this example demonstrates a feature that
might be called open classes or inter-type declarations,
the important point is that you can maintain the separation
of this aspect of a class, so you can reuse the class (or
the aspect) without modification in different contexts,
and so you need not redo "beanness" for each class (or
revisit what it takes to be a bean for each aspect).  It's
this modularity that we are aiming for (and where AspectJ
doesn't provide it, we're trying to do better).

With a concrete understand of crosscutting, you begin to see
in your own code that AspectJ works for any design having
crosscutting concerns, whether they are GUI's or scientific
libraries.

There are more recent technologies claiming to do AOP that
introduce themselves by way of gee-whiz example.  The examples
can be compelling, but often the technologies are not suitable
for general-purpose use, either because the framework is
limited to something like that example, or because it is
so difficult to write crosscutting components that it
requires a specialist (who might prefer the fame or
income of providing fish to handing out fishing poles).
By contrast, AspectJ's more principled design and
language-level support results in users being able to
write solutions that the language designers never
envisioned, and the AspectJ designers support users
writing their own code because it validates the language
itself.  Starting from principles helps you not only
recognize new AOP features/solutions as such, but also
avoid the trap of taking a particular solution as AOP
and the confusion from purveyors who would like to
maintain AOP as the domain of a specialist class.

Beyond this path from the docs index page, there are some
publications and new things in the AspectJ CVS docs module.
Two presentations evolved over the years, an introductory
tutorial (long available online), and an intermediate
hands-on tutorial (just recently added).  Also, there is a
collection of sample code that aims to include just about
anything of interest, suitable for those who've been
introduced to AOP/AspectJ but are looking for a way to say
something in particular.  (I'll present this soon as an
online-only document, once some promised contributions
come in.)  Finally, there are books that walk you through
particular idioms and solutions which can be very helpful
if they overlap with your concerns.  The books on AOP/AspectJ
keep getting better, and we hope that trend continues.

As Gregor notes in his recent interview, AOP is now going
from invention (with AspectJ) through a very fruitful
innovation phase.  Something may come along which is
superior to AspectJ for doing AOP.  Regardless of the
outcome, we hope that this competition can proceed on the
merits and with clear understanding, so users benefit by
better ways to do AOP, rather than being confused by
conflicting claims and approaches.

Wes

-- main page for downloadable documentation, with paths for new users
http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/index.html

-- links to books and articles (and Gregor's interview)
http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/publications.html

-- accessing CVS to see the tutorials and samples sandbox
http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/faq.html#q:buildingsource


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