I've just watched Luis's Meetup presentation on WireBox, and am quite
excited about AOP - it's the first time I've really understood what it
does and what its benefits are.
One thing that's not immediately clear (to me!) either from the
presentation or the Wiki:
In the example, the save() method implements both the logging and
transaction aspects. But how do I specify in which order these should
be executed (i.e. ensure that the logging aspect runs first and in
turn calls the transaction aspect)?
Sorry if this is a stupid question, or if I've missed something
obvious...
It is not really a stupid question, but the idea behind AOP is to maximise
code reuse. The example you are talking about highlights the need to log
before and have a transaction, as well as the transaction itself.
The idea is that you write what you need too, the logging and transaction is
just a sample of what you might do. So in other words the execution order is
defined by what you write.
Does that make sense?
Regards,
Andrew Scott
http://www.andyscott.id.au/
From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Seb Duggan
Sent: Saturday, 2 July 2011 12:18 AM
To: ColdBox Platform
Subject: [coldbox:10614] AOP: order of execution of aspects
I've just watched Luis's Meetup presentation on WireBox, and am quite
excited about AOP - it's the first time I've really understood what it
does and
what its benefits are.
One thing that's not immediately clear (to me!) either from the
presentation
or the Wiki:
In the example, the save() method implements both the logging and
transaction aspects. But how do I specify in which order these should be
executed (i.e. ensure that the logging aspect runs first and in turn calls
the
Makes sense, yes - but the diagram shows:
Logger -> proceed() ==> Transaction -> proceed() ==> save()
which shows the chaining of aspects - and as you say, code reuse should be maximised. So I’d want to keep the logging and transaction as separate aspects, but implement them both on my save() method.
I still don’t understand how you’d say which order these would execute in…
They execute in the order that you bind them using bindAspects() method. It has an aspects argument which can be a list or array. So order is important.
Thanks Luis - makes perfect sense now!
Just got a bit confused by the fact that in the example you bind each of the aspects individually, but don't show them both being bound together...
Great meetup presentation, by the way - really helped me get my head around a couple of concepts!
Following up on that, I assume that means that if you're going to bind multiple aspects to a method, you would need to do so explicitly using bindAspect(), rather than via auto binding...
Auto binding depends when you map the aspect. So if you map aspect A first and then aspect B, that’s the order they execute for self-binding aspects.
For normal binding, you can define more than 1 aspect on a specific method via that argument.
Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com
ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com
Social: twitter.com/lmajano facebook.com/lmajano