"An aspect is a modular unit which is disseminated
by the structure of other functional units"
(Gregor Kickzales)
"Aspect-Oriented Programming deals with cross-cutting themes and descriptions, design and implementation of these themes" (Karl Lieberherr).
"Meta-objects seem to be a natural place to implement aspects" (Charlotte Pii Lunau).
Aspect-Oriented Programming (AOP)
When designing a software system, we are forced to choose a main paradigm (or dominant conceptual dimension) of modular type (object, functional, procedural, etc.). This is the so-called "tyranny of the dominant decomposition". But there are code fragments that are scattered in the system modules and that constitute cross-cutting functional units (cross-cutting concerns). These are called "aspects". An aspect of a program or code is a modular unit of the program that is scattered in other modular units of the program.
The −AOP− is a new programming paradigm that aims to collect these cross-cutting functionalities into centralized add-on modules. An aspect is a cross-cutting functionality that is implemented modularly and separately from the rest of the system.
AOP does not affect the core functionality of a system, but facets of its behavior: collateral or cross-cutting issues, properties or areas, which affect all components of that system, regardless of their structure or functional dependency on each other.
The AOSD (Aspect Oriented Software Development) website defines AOP as "A programming paradigm in which the cross-cutting issues that permeate a system are isolated and extracted into separate modules called aspects."
The implementation of the AOP paradigm consists of:
Identify the different aspects present in a system.
Detect the possible dependencies between the different aspects.
Integrate the aspects of a system in a simpler, clearer and more orderly way.
Types of aspects
There are different types or categories of aspects. They can be low-level or high-level. They can be functional or non-functional. They can be design or implementation. Some examples are:
Implementation.
Object persistence.
Memory management.
Performance.
Systemic.
Synchronicity of concurrent processes.
Coordination or collaboration between processes.
Transaction management.
Security.
Error handling.
Encryption.
Access control.
Redundancy.
Authentication.
Restrictive.
Memory.
Execution time.
Devices.
Object size, structure and values.
Quality of Service (QoS).
Presentation of information.
Response time.
Process.
Event logging.
Input data verification.
Notification.
Program testing.
Tracing.
Presentation of intermediate results.
Business.
Business rules.
Parameters.
Operating Systems (Input/Output).
Caching (storage in memory of a series of data for quick access).
Buffering (buffering used to compensate for the speed difference between an input/output device and the processor).
Distributed systems.
Interprocess communication.
Synchronization.
Persistence −the storage and retrieval of an application's data in secondary storage− is a typical example of a cross-cutting theme or aspect. An application can be developed without considering the persistence issue and address it at a later stage. This approach has the advantage that, if the storage type is changed, it is sufficient to change only the persistence module, without the need to change the functionality of the system. The same advantage applies to the other aspects.
Advantages of AOP
The application of paradima AOP has many advantages:
Higher level of abstraction.
Clearer, simpler, more structured and more modular design.
Higher software quality, with centralized code, smaller, easier to understand, debug and maintain, and reusable.
Minimization of dependency relationships between aspects, as well as possible conflicts between aspects.
Implementation of the AOP
The traditional solution is to repeat the corresponding code in the different modules that need it, because there was no way to encapsulate in a single module something that cut across multiple modules in the system. The result was tangled code.
Today, AOP is implemented by the following components:
A base (general purpose) language to define the basic functionality.
One or more aspect-oriented languages, which can be:
Specific.
These are special languages to deal with different concrete aspects in concrete domains. These languages usually impose restrictions on the use of the base language to ensure its correct use. Examples: COOL (Concurrent Object Oriented Language), RIDL (Reliable Interface Design Language), etc.
General.
They are valid languages for all kinds of aspects. They are more open and it is the responsibility of the programmer to use them correctly. Examples: AspectJ (a Java extension), AspectC++ (a C++ extension), etc.
Join Points.
They are defined in the base application and indicate the locations where the aspects are to be applied.
PointCuts.
The set of conditions necessary for an aspect module to be executed at a junction point.
Execution Points (Execution Points).
These are the modules that are executed when a cut point is activated at a junction point.
Advices.
These are the actions that are executed at each junction point and triggered by the corresponding cut points.
Weaver of aspects.
It is responsible for interlinking the base language with the aspect languages through junction points, generating a complete program. The interlinking can be static (at compile time) or dynamic (at run time).
Decomposition of a system by aspects
A software system admits several possible decompositions, according to the different aspects to be considered. But, according to the main functionality that you want to assign to it, there is a dominant decomposition.
If the main functionality and those corresponding to the aspects were integrated into a single decomposition, the result would be somewhat chaotic, since the processing code for each aspect would be scattered throughout the code, with the resulting complexity.
The solution to this problem consists of:
Replacing the classical decomposition of a system into conceptual blocks (functions, procedures, objects, etc.) by the aspectual decomposition, where the classical decomposition is really another aspect, although it is the main one.
Program the aspectual process independently, in the form of components or modules, in order to achieve more clarity.
Link the main process with the processes of the different aspects.
History of the AOP
The AOP paradigm has been the result of the convergence of several independent lines of research that began with the fundamental principle of modular software decomposition, pioneered by Edsger Dijkstra and David Parnas.
In the 1970s, David Parnas published "On the criteria to be used in decomposing systems into modules", in which he advocates creating functional modules and data modules. Data modules were the origin of object-oriented programming.
In 1984, meta-programming appeared: programs that create or manipulate other programs or themselves as data.
In 1992, composition filter programming (composition filters programming) appeared [Aksit et al. 1993]. Filters allow to express different kinds of aspects in a uniform way in OOP (Object Oriented Programming) by means of independent and self-sufficient objects, Aspects such as inheritance, delegation, synchronization, queries, constraints, interactions, etc. Each aspect is defined by a filter. Aspects defined by filters can be easily combined and are reusable.
In 1995 the first references to the term "aspect" appeared by the Demeter research group in the technical report on separation of concerns in which they described certain techniques for handling those scattered issues in a software system. The Demeter group was investigating adaptive programming, a predecessor of AOP. The Demeter group gave the first definition of the concept of aspect: "An aspect is a unit that is defined in terms of information from other units."
A concern is a topic, issue or aspect that needs to be addressed to solve a problem. The separation of concerns consists of identifying and encapsulating (modularizing) the software corresponding to each concern.
In 1996, Gregor Kickzales and his team at PARC (Palo Alto Research Center) presented the concept of Aspect-Oriented Programming. From this author is the current definition of aspect: "An aspect is a modular unit that spreads through the structure of other functional units".
The group's work was initially based on object-oriented programming, computational reflection using meta-objects. A meta-object is an object that creates or manipulates another object (or itself). The object to which the meta-object refers is called the "base object".
Between 1995 and 1997 languages were developed that contemplated aspects: RG, AML (Annotated MatLab), ETCML (Evaluation Time Control Meta Language), DJ (Distributed Programming, an extension of Java).
In 1998 the first workshop on AOP was held. In the same year the first version of the AspectJ language, an extension of Java, was presented. Currently, AspectJ is the most widespread and widely used aspect-oriented language.
Aspects Implementation in MENTAL
With MENTAL everything is simplified and clarified:
Universal language.
In MENTAL no special language or any extension of a base language is needed to be able to design and deal with design aspects. Only in the case that the aspect affects low level implementer issues, then we would need a specific language to handle that aspect. With MENTAL all the complexity associated with the current aspect solution is avoided. No join points, no cut points, no weaver is needed.
In MENTAL everything is simpler and more straightforward. The complexity derives from trying to integrate the aspects at the same level of the base language, instead of contemplating them from a higher level (meta level).
AOP is usually considered to be an extension or complement to OOP. In fact, AOP has emerged from OOP. But in MENTAL the aspects are independent of the main paradigm used, and different programming paradigms can also be used in them.
Target level.
The (simple) solution to the problem of aspects consists of being at a higher level than the base level and using a meta language on top of the base language. This is done by means of generic expressions, which can be of many kinds: parameterized or not, conditional, substitution, etc. The meta language has all the power of the base language, but within generic expressions.
The advantages of using this approach are: 1) Each aspect can be managed separately and programmed independently; 2) Different aspects can be easily integrated and related through the environment.
Generic expressions are the tool for programming aspects. They allow to detect situations or conditions and to activate specific treatment modules. The generic expression "detects" a condition and processes it, a condition that can occur at any point in the execution code.
Aspect types.
The domain of possible aspects is broadened and generalized. Aspects can be applied to all types of expressions, both active (processes) and passive (data). Attributes, conditions, variables, assignments, etc. can be managed.
In MENTAL, an aspect can be anything: an arithmetic operation, a condition, a substitution, an execution, etc., both particular and general. In general, an event produced at the base level (before or after the evaluation).
Higher order aspects.
Higher order aspects, i.e. aspects of aspects, can be implemented. They are implemented by means of different meta levels: the meta level defines the aspects associated with the base level, the meta-meta level defines the aspects of the meta level, etc.
Virtual aspects.
Virtual aspects can be defined, i.e. aspects defined by combination of other previously defined aspects.
Flexible environment.
A criticism that has been made of AOP is the difficulty of establishing the interaction between the different aspects of the system. With MENTAL this task is easy, since it has a flexible, open and dynamic environment, where one aspect is able to self-modify, affect other aspects, create new aspects, eliminate them, etc.
Control flow.
Another criticism that has been leveled at AOP is that the control flow is confusing, something close to the harmful GOTO statement. In MENTAL the control flow is clear: the code associated with an event produced by an event is executed before or after evaluating any expression. The link between the base level and the target level is automatic at the execution level.
Computational reflection.
A generic expression is a meta-expression because it sits at a higher level from which it observes what is happening and makes decisions. It can influence the base level and even modify it. In traditional computational thinking, a base level object has only one meta-object, with a close relationship between the two. In MENTAL, the meta-level has all possibilities, it is not restricted.
Aspects vs. Events.
In MENTAL, aspects are managed from events defined in generic expressions. In this sense, AOP and EOP (event-driven programming) are technically equivalent. POE focuses on core functionality and AOP on cross-cutting functionality.
Universal paradigm.
MENTAL is a universal paradigm where the boundaries between the different particular paradigms are blurred. In fact, the same linguistic resources are applied in Event Oriented Programming, in Constraint Oriented Programming, in Reflexive Programming, in Agent Oriented Programming, etc.
Examples
We want to know how many successive values the variable x takes along the execution of a program.
Concurrent process structure.
The processes p1 and p2 must be started simultaneously when the condition k=1 is met, and when both are finished, the process p3 must be executed.
〈( (k = 1) → ((k = 0) ({p1 p2} p3)) )〉
The restoration of the variable k is important so that the condition is not fulfilled again.
Addenda
Related techniques
Many programming techniques include concepts similar to those of aspect-oriented programming such as:
Reflective Systems.
Adaptive Programming.
Subject-Oriented Programming.
Reflective Systems
A reflective module is a module that sits at a higher level (target level) from which it observes what happens at the base level and makes decisions. It can even modify the base code. It is also called "computational reflection" [Maes, 1987]. In traditional computational reflection, a base level object has at most one meta-object.
Adaptive programming
An object-oriented software design and development methodology that is evolutionary, i.e., incremental, progressive, and incremental.
The design is made from a brief initial specification, of informal type, in which the objects and the operations are separated. The objective is to maintain as loose a coupling as possible between objects and operations, so that modifications to one part have minimal impact on the others.
The software is not developed directly at the object level, but at such a level that it can be easily adapted to a wide variety of contexts. The result is more flexible, more compact and more intelligible software.
An adaptive program consists of n parts a1, ..., an, where each part ai expresses an aspect as independent as possible from the rest. The executable program is specified by a function c of combinatorial type between those n parts: c(a1,…,an).
The Demeter group has been the pioneer of Adaptive Programming. The so-called "Demeter law" was announced in 1987. This law was later improved by Karl Lieberherr in the context of Aspect-Oriented Programming.
Adaptive Programming is now considered to be a special case of Aspect-Oriented Programming.
Subject-Oriented Programming.
It is a programming technique that complements OOP to solve the problems of interoperability, cooperation and integration of applications.
Systems are modularized by initially considering topics or aspects, both static and dynamic (error detection and management, persistence, etc.). Objects and applications are built from these modules. Aspect modules come into action with events of the type "before" or "after" an operation. The "Join Points" are thus realized at the operation level, as opposed to the classical approach, which are at the statement level.
Topic Oriented Programming was pioneered at IBM by Harold Ossher and Hill Harrison.
Topic-Oriented Programming is now considered to be a form of implementation of Aspect-Oriented Programming.
Bibliography
Aksit, M; Wakita, K; Bosch, J; Bergmans, L; Yonezawa, A. Abstracting Object Interactions Using Composition Filters. In Object-based Distributed Processing, O. Nierstrasz and M. Riveill (eds.). LNCS’79, pp. 152-184, Springer-Verlag, 1993.
Demeter Research Group: http://www.ccs.neu.edu/ research/demeter
Gradecki, Joseph D.; Lesiecki, Nicholas. Mastering AspectJ: Aspect-Oriented Programming in Java. John Wiley & Sons, 2003.
Harrison, William; Ossher, Harold. Subject-Oriented Programming (A Critique of Pure Objects). OOPSLA’93 pp. 411-428, 1993.
IBM subject-oriented programming: http://www.research.ibm.com/sop/
Kiczales, G. Aspect-Oriented Programming. Proceedings of ECOOP, Springer Verlag, LNCS 1241, 1997.
Kiczales, G.; Hilsdale, E; Hugunin, J.; Kersten, M.; Palm, J.; Griswold, W. An Overview of AspectJ. Proceedings of ECOOP, Springer Verlag, LNCS 2072, 2001.
Kiczales, G.; Lamping, J.; Mendhekar, A.; Maeda, C.; Lopes, C.; Loingtier; Irwin, J. Aspect-Oriented Programming. Xerox Palo Alto Research Center, 1997.
Kiczales, G.; Rivieres, Jim des; Bobrow, Daniel G. The Art of Metaobject Protocol. The MIT Press, 1991.
Lieberherr, Karl. Adaptive Object-Oriented Software: The Demeter Method with Propagation Patterns. PWS Publishing Co., 1996.
Pattie, Maes. Computational Reflection. Ph. D. Thesis. Technical Report 87-2. Artificial Intelligence Laboratory. Vrije University Brussel, 1987.
Pii Lunan, Charlotte. Is Composition of Metaobjects = Aspect Oriented Programming? Internet.
Rashid, Awais; Chitchyan, Ruzanna. Persistence as an Aspect. Internet, 2003.
Reina Quintero, Antonia María. Visión General de la Programación Orientada a Aspectos. Depto. De Lenguajes y Sistemas Informáticos. Facultad de Informática y Estadística, Universidad de Sevilla, 2000. Disponible online.
Videira López, Cristina. Aspect-Oriented Programming. An Historical Perspective. What’s in a Name? ISR Technical Report. University of California Irvine, Dec. 2002. Disponible online.