
2454 JOURNAL OF SOFTWARE, VOL. 9, NO. 9, SEPTEMBER 2014 Aspect-Oriented Programming to Improve Modularity of Object-Oriented Applications Jose M. Felix Principality of Asturias, Computer Science Department, Oviedo, Spain Email: [email protected] Francisco Ortin University of Oviedo, Computer Science Department, Oviedo, Spain Email: [email protected] Abstract— The separation of concerns design principle modularized with the mechanisms provided by common improves software reutilization, understandability, object-oriented languages [3]. extensibility and maintainability. By using the object- The different (functional and non-functional) oriented paradigm, it is not always possible to separate into requirements demanded to an application are called independent modules the different concerns of an concerns application. The result is that the source code of crosscutting software [4]. The Separation of Concerns (SoC) concerns are tangled and scattered across the whole design principle is aimed at separating a computer application. Aspect-oriented programming offers a higher application into distinct modules, such that each one level of modularity, providing a solution for the code addresses a separate concern [4]. tangling and scattering problem. To show how aspect- Some concerns cannot be directly modularized in oriented programming can be used as a suitable mechanism classic object-oriented languages because those languages to improve the modularity of object-oriented applications, have not sufficient expressiveness to implement them in this divulgative article presents the implementation of a independent modules. In that case, the implementations typical design pattern following both the object- and aspect- of those concerns cut across multiple abstractions in a oriented paradigms. The two approaches are compared from the modularity perspective, establishing a discussion program. For this reason, these concerns are said to be on the benefits provided and is current use. crosscutting [5]. Figure 1 shows a real example. This figure presents the modularization of the Apache Tomcat Index Terms—aspect-oriented programming, modularity, application server implementation [6]. Each vertical bar crosscutting concerns, AspectJ, separation of concerns shows one implementation module, and its size is proportional to the number of lines of code. The left-hand side of Figure 1 shows in red the lines of code whose I. INTRODUCTION concern is XML document parsing. It can be seen how that functionality is placed in one single module. The Designing modular systems is fundamental for right-hand side of Figure 1 shows the source code managing software complexity and improving its distribution of the logging concern. This is an example of reusability, understandability, extensibility and a crosscutting concern: its source code is not placed in a maintainability [1]. At the implementation level, unique module (code scattering), and every module, programming languages provide mechanisms to perform including XML parsing, contains code of this concern this modularization. Some common features of object- (code tangling). This code scattering and tangling issues oriented languages used to facilitate the modularization of indicate that the implementation-level modularization is application abstractions are methods, classes, packages, not appropriate, leading to reusability, understandability namespaces and annotations. There exist some other and maintainability limitations [4]. modularization mechanisms, not directly supported by The main contribution of this divulgative paper is a programming languages, which provide a higher level of practical analysis of how Aspect-Oriented Programming abstraction. Examples of these mechanisms are (AOP) provides an alternative mechanism to solve the components, design patterns, application frameworks, code tangling and scattering problems in the and architectural patterns. implementation of crosscutting concerns. In order to do In the software development process, there are cases that, Section II introduces the main AOP concepts and when some system abstractions cannot be directly AspectJ, one of the most widely used AOP tools modularized with the mechanisms provided by a nowadays [7]. Section III presents an example of a programming language [2]. A vector sorting algorithm common design problem, comparing the object- and can be implemented in a unique class method. However, aspect-oriented implementations. Afterwards, the functionalities such as error detection and correction, suitability of AOP for improving modularity is discussed logging, persistence and security cannot be directly © 2014 ACADEMY PUBLISHER doi:10.4304/jsw.9.9.24454-2460 JOURNAL OF SOFTWARE, VOL. 9, NO. 9, SEPTEMBER 2014 2455 a) Distribution of the XML parsing concern b) Distribution of the logging concern Figure 1. Distribution of concerns (source code per module) in the implementation of Apache Tomcat [6]. Modules of the Concerns Final Application Requirements Functional Concern 1 Functional Concern 2 Functional Concern 3 Weaver Persistence Concern Logging Concern Figure 2. Weaving the different concerns identified from the application requirements. in Section IV, and the conclusions and future work are other concerns (e.g., logging). However, the rest of presented in Section V. concerns are scattered among multiple modules, and tangled with the code of other concerns. Therefore, AOP II. ASPECT-ORIENTED PROGRAMMING raises the level of abstraction, offering the programmer a modularization mechanism superior to that provided by Separating the different concerns of an application is object orientation. The aspect weaver is the tool that an objective in all the steps of the software development translates the aspect-oriented abstractions into the object- process. Aspect-orientation is a particular mechanism to oriented ones. achieve the SoC goal. Aspect-Oriented Software There exist two approaches for representing concerns Development (AOSD) focuses on the identification, in AOP. Asymmetric AOP distinguishes the base code specification and representation of cross-cutting concerns (traditional classes in the classical object orientation) and their modularization in all the steps of the software from the aspects. Aspects represent crosscutting concerns development process. Therefore, aspect-orientation can that, due to the aspect weaver, can be modularized. be applied to requirement engineering, business process Therefore, in asymmetric AOP, an aspect must be used to management, system architecture, modelling and design be woven with a class (or another aspect). AspectJ is an [8]. In this article we focus on aspect-oriented example tool that provides asymmetric AOP [7]. On programming, which is centered on the programming contrary, symmetric AOP is based on the unique concept techniques and tools to support the modularization of of class/aspect. Any class can act as an aspect and be concerns at the level of the application source code [4]. woven with any other class (or aspect). Hyper/J is an As shown in Figure 2, the different concerns of an example of symmetric AOP [9]. application are identified from its requirements. Before In general, aspect weaving is performed statically, its implementation, the application concerns are before application execution. AspectJ also provides load- conceptually separated. These concerns comprise both time aspect weaving, when classes are about to be loaded functional (i.e., problem domain) and non-functional (e.g., into memory by the virtual machine. There are also AOP persistence or logging) requirements. The objective of tools that allows aspect weaving and unweaving at AOP is to modularize all these concerns. The aspect runtime, when the application is being executed [10]. weaver is the tool that takes the different concerns of an These dynamic weavers adapt running applications at application and generates the target program. If the final stable points of execution. Examples of these dynamic application is coded in an object-oriented language, such AOP tools are the JAsCo, PROSE and DSAW platforms as Java or C#, the target code of the different concerns [11]. may be tangled and scattered. Figure 2 shows how the Aspect-oriented programming has been included in final implementations of the functional concerns 1 and 2 widespread application server frameworks such as JBoss are placed in one single module, tangled with the code of or Spring. There are other implementations, such as JAC, © 2014 ACADEMY PUBLISHER 2456 JOURNAL OF SOFTWARE, VOL. 9, NO. 9, SEPTEMBER 2014 «interface» Subject «interface» -observers Observer + addObserver(Observer) + removeObserver(Observer) * + update() + updateObservers() Alarm Timer Clock - hour: int - hour: int + addObserver(Observer) -clock - minute: int - minute: int + removeObserver(Observer) - second: int System.out.println("Tick"); - second: int + tick() 1 - message: String this.updateObservers(); + updateObservers() + incrementOneSecond() + checkAlarm() + update() + update() for(Observer observer:observers) observer.update(); this.incrementOneSecond(); this.checkAlarm(); System.out.println(this); Figure 3. Object-oriented implementation of the Observer design pattern. aimed at developing an aspect-oriented middleware layer. Each Subject holds a collection of Observers by Another criterion to classify AOP tools is their domain. means of the observers field, and the addObserver They could be used for general purposes, such as AspectJ, and removeObserver methods. Although there
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages7 Page
-
File Size-