Tuesday, May 27, 2014

Aspect-oriented Programming (AOP) - Introduction - 1

In this post I will start writing a bit about Aspect-oriented programming, in a future post about aspect implementation in AspectJ, and I hope later explain about some ideas of combining formal methods with this paradigm.
I assume that you all know what object-oriented programming is, and in particular know some object-oriented language. Basically, we define classes from which we can instance objects, which are the fields and type of each instance of the class, and to which messages / methods the object responds and how.
However, when implementing an application there are crosscutting concerns that affect multiple objects, and get tangled in their implementation, and scattered along many objects [1]. Typical examples are logging, persistence, transaction management, gui updates. These are examples of aspects [2] applicable to multiple systems, but there could be aspects defined specifically for each application, when are the points updated in a game, which discounts to apply to a purchase, etc..
To represent this crosscutting concerns modularly aspects indicate where the particular code should be applied, and what should be do. For example, we could say "every time a public method is called, log it". This is expressed in a different module that looks like a class (but is an aspect), and the locations are expressed as a query. For example in AspectJ (an aspect-oriented extension for Java), that location is expressed as call(* public *(..)), i.e. call to a public method (first *: for any return type; second *: for any method name; ..: for any set of arguments).

References:
[1] Tarr, Peri, Harold Ossher, William Harrison, and Stanley M. Sutton Jr. "N degrees of separation: multi-dimensional separation of concerns." In Proceedings of the 21st international conference on Software engineering, pp. 107-119. ACM, 1999.
[2] Kiczales, Gregor, John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin. Aspect-oriented programming. Springer Berlin Heidelberg, 1997.

No comments:

Post a Comment