Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
research:mao:advice-dispatch [2011/06/17 13:27] – ebodden | research:mao:advice-dispatch [2011/06/17 13:40] (current) – ebodden | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | In the FSE/NI paper we had the following example | ||
+ | < | ||
+ | jpi void buying(Item item, float price, | ||
+ | int amount, Customer cus) | ||
+ | extends checkingOut; | ||
+ | |||
+ | aspect Discount { | ||
+ | void around checkingOut(Item item, float price, int amt, Customer cus) { | ||
+ | int factor = cus.hasBirthday()? | ||
+ | proceed(item, | ||
+ | } | ||
+ | void around buying(Item item, float price, | ||
+ | int amt, Customer cus) { | ||
+ | int factor = (amt > 10) ? 0.85 : 1; | ||
+ | nextadvice(item, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Here, '' | ||
+ | |||
+ | We observed the problem that this is assymetric: this way, one can apply the '' | ||
+ | |||
+ | Eric B. here proposes an alternative semantics, which is closer to AspectJ and executes pieces of advice in order of declaration. Consider this slightly modified code: | ||
+ | |||
+ | < | ||
+ | aspect Discount { | ||
+ | void around checkingOut(Item item, float price, int amt, Customer cus) { | ||
+ | int factor = cus.hasBirthday()? | ||
+ | proceed(item, | ||
+ | } | ||
+ | void around buying(Item item, float price, | ||
+ | int amt, Customer cus) { | ||
+ | int factor = (amt > 10) ? 0.85 : 1; | ||
+ | proceed(item, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Here, we call '' | ||
+ | At the position marked '' | ||
+ | |||
+ | Now consider the case in which we dispatch a '' | ||
+ | |||
+ | Note that this design allows us to flexibly change the ordering in which the pieces of advice will apply. The following declaration would induce the inverse dispatch ordering: | ||
+ | |||
+ | < | ||
+ | aspect Discount { | ||
+ | void around buying(Item item, float price, | ||
+ | int amt, Customer cus) { | ||
+ | int factor = (amt > 10) ? 0.85 : 1; | ||
+ | proceed(item, | ||
+ | } | ||
+ | void around checkingOut(Item item, float price, int amt, Customer cus) { | ||
+ | int factor = cus.hasBirthday()? | ||
+ | proceed(item, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Here, on a '' | ||
+ | |||
+ | ===== Dispatch sequence across aspects ===== | ||
+ | |||
+ | The above semantics based on ordering is problematic when multiple aspects advise the same joinpoint type hierarchies. Which advice should then execute first? In this case Eric B. proposes to resort to a '' |