AOP technology research-AOP Overview

Source: Internet
Author: User

1 Preface


1.1 Software Programming Technology Development


Software Programming Technology and programming language are inseparable. Over the past few decades, programming languages have continuously increased support for abstract mechanisms, from machine languages to assembly languages to advanced languages to object-oriented languages. The emergence of each new programming language brings about a leap in software programming methods. When the Assembly language appears, developers do not directly use 0-l encoding. Instead, they use symbols to represent machine commands, making programming easier. When the program scale continues to grow, there are advanced languages, such as Fortran, C, and Pascal, which make it easy to compile complex programs, developers can better cope with increasingly complex code. Software development methods at this stage are called process-oriented ". However, with the rapid development of the software industry, larger and more complex software systems are proposed in the demand. Even if developers use structured program design methods, it is still difficult to grasp the overall situation of software development. In this case, as a tool to reduce development complexity, object-oriented languages such as C ++ and Java have been generated, and object-oriented programming has also developed, the software programming methodology also transits from process-oriented to the object-oriented (OOP) era. It is not hard to find that programming technology and programming language define the communication mode between people and machines [1]. Each new technology provides some new methods to solve the problems that have not been well solved. For example, machine-independent code can be used to abstract obscure 0-1 commands: process-oriented programming languages allow people to use structured design methods to construct more complex systems; by encapsulating the implementation details of specific data and methods through classes in object-oriented programming languages, people can divide complex systems in detail. Every new technology provides a more natural way to map system requirements into programming structures. The continuous development of programming technology allows people to create more complex systems, and vice versa. People allow more and more complex systems because new technologies can be used to deal with this complexity.


1.2 OOP

1.2.1 concept of OOP


Oop: object-oriented programming (Object-Oriented Programming) is a type of programming paradigm and a programming technology. It uses objects as the basic unit of a program and encapsulates programs and data to improve software reusability, flexibility, and scalability.
Oop is a method to construct software development by using objects, classes, inheritance, aggregation, message transmission, and polymorphism. It tries its best to use human natural thinking methods in system construction. Its main concepts [2] are as follows:
(1) object: an object used to describe objective things in the system. It is a basic unit of the system, an object consists of a group of attributes and a group of services that operate on these attributes.
(2) Class: a set of objects with the same attributes and services. It provides a unified abstract description for all objects of the class, it includes attributes and services.
(3) Encapsulation: combines object attributes and services into an independent system unit, and hides the internal details of objects as much as possible.
(4) Inheritance: Objects of special classes have all the attributes and services of their general classes. They are called special classes that inherit general classes.
(5) polymorphism: Generally, attributes defined in a class or services inherited by special classes can have different data types or show different behaviors.

Oop can be seen as an idea that contains various independent and mutually called objects in a program. This is just the opposite of the traditional idea: in traditional programming, a program is regarded as a collection of functions, or directly a series of commands issued to computers. Every object in object-oriented programming should be able to accept, process, and transmit data to other objects, so they can be considered as a small "machine", that is, an object.

1.2.2 advantages of OOP

Before the emergence of OOP technology, structured design was the mainstream of program design. Structured Programming is also known as process-oriented programming. In process-oriented programming, requirements are considered as a series of tasks that need to be completed. functions are used to complete these tasks and focus on functions to solve the problem. The function is process-oriented, that is, it focuses on how to complete the specified task according to the specified conditions. In multi-function programs, many important data is stored in the global data zone, so that they can be accessed by all functions, and each function can have its own local data. Figure 1.1 shows the relationship between functions and data in process-oriented programming.


Figure 1.1 relationship between functions and data in process-oriented programming [3]

This structure can easily cause global data to be accidentally modified by other functions, so the correctness of the program is not guaranteed. One of the starting points of object-oriented programming is to make up for the disadvantages of process-oriented programming. In object-oriented programming, an object is a basic element of a program. It closely links data and operations, and prevents data from being accidentally changed by external functions. Figure 1.2 shows the relationships between objects, data, and methods in object-oriented programming.


Figure 1.2 relationship between objects, data, and methods in Object-Oriented Programming [3]
Comparing OOP and process-oriented programming, you can also obtain other advantages of object-oriented programming [4]:
(1) The concept of data abstraction can change internal implementation while keeping external interfaces unchanged, so as to reduce or even avoid external interference.
(2) The Inheritance mechanism can not only greatly reduce redundant code, but also easily expand existing code, which improves the coding efficiency and reduces the coding error probability, reduce the difficulty of software maintenance.
(3) combined with object-oriented analysis and design, objects in the problem domain can be directly mapped to the program to reduce the conversion process of intermediate links in the software development process.
(4) through the identification and division of objects, the software system can be divided into several relatively independent parts, which facilitates the control of software complexity to a certain extent.
(5) the object-centered design helps developers grasp problems from both static attributes and dynamic methods to better implement the system.
(6) through the aggregation and Union of objects, the internal structure and external functions of objects can be expanded under the principle of encapsulation and abstraction, in this way, the object function is changed from low-level to advanced.

1.2.2 disadvantages of OOP

Object-Oriented programming methods have caused significant changes in the field of software development, greatly improving the productivity of software development and bringing light to solving the software crisis. However, like other programming methods, object-oriented programming is not perfect. For example, the use of object-oriented programming can effectively solve the problem of role division in software systems and modularize many of the concerns in software development, and encapsulate the implementation details of these concerns in the class. However, there is another type of attention in the system. They are not specific to a certain module or class. They may span multiple modules or classes, for example, the log function can be referenced by many modules in the system. The method used by Object-Oriented Programming to deal with such attention points is not ideal, resulting in confusion and decentralization of code [5 ~ 7]. You can use a simple example to illustrate the problems caused by cross-concern implementation by programming to the object. Here we provide an implementation framework that encapsulates the business logic:
Public class businessclass extends basebusinessclass {
// Core data member
// Other data members: log streams, flags that ensure data integrity, etc.
// Method for reloading the base class
Public void implements msomeoperation (operationinformation info ){
// Security verification
// Check whether the incoming data meets the Protocol
// Lock the object to ensure data integrity when other threads access it
// Check whether the cache contains the latest information
// Record the start time of the operation
// Perform core operations
// Time when the recorded operation is completed
}
// Some similar operations
Public void save (persitancestorage PS ){}
}
In the above Code, there are two problems: first, other data members are not the core concerns of this class; second, the implementation of the performsomeoperation () method has done a lot of things beyond the core operations, it handles peripheral operations such as comrade, verification, thread security, protocol verification, and Cache Management, and these peripheral operations are also applied to other classes. The above two problems are ultimately caused by OOP's failure to modularize the requirements that are shared by multiple modules in the system.

To solve the modular implementation of cross-cutting concerns, Aspect-oriented programming, a new programming technology, came into being.

2 AOP Overview
2.1 AOP Ideology
AOP: Aspect Oriented Programming for aspect programming.
Aspect-Oriented Programming (also called Aspect-Oriented Programming): aspect oriented programming (AOP) is currently a hot topic in software development. AOP is actually a continuation of the gof (Observer Design Pattern) design pattern, emphasizing the decoupling between the caller and the called. No developer provides a mechanism to describe crosscutting concern, in addition, the cross-concern is automatically woven into the (weaving) to the object-oriented software system, thus implementing the modularization of the Cross-concern. By dividing the aspect (aspect) code, it is easy to deal with cross-cutting concerns. Developers can change, insert, or remove system aspects during compilation, or even Reuse System Aspect [2]. AOP can be used to isolate all parts of the business logic, thus reducing the Coupling Degree between each part of the business logic, improving the reusability of the program, and improving the development efficiency.
When designing a new system, we need to focus on how to handle the main core functions. For commercial applications, this is the basic business logic. For example, in a banking application system, the core module is used to process the banking transactions used by depositors: in a retail application system, the core module is used to process the commodity purchase and inventory management services. In these two applications, there are also some common points of concern throughout the system, such as logging, user authentication, data persistence, and other elements shared by many core business modules. These system-wide features distributed across multiple modules are called cross-node concerns [, 10]. Aspect-oriented programming (AOP) is used to deal with these cross-cutting concerns. Although object-oriented programming (AOP) is the most widely used method of processing core concerns [5], it is not ideal for dealing with cross-cutting concerns. The coupling between the core concern points and the cross-cutting concerns implemented by typical OOP is not ideal. To add new cross-cutting features or modify the existing cross-cutting functions, all related core modules must be modified to make system maintenance and expansion difficult, the root cause of this phenomenon is that the implementation methods of cross-cutting concerns in OOP are scattered within each core concern.
AOP is a new technology. Its core idea is to modularize the cross-cutting concerns and core concerns in the system. The cross-cutting concerns are modularized through the aspect (aspect), and the core concerns are through the class) implement modularization, and then use a tool similar to the compiler-aspect Weaver [5 ~ 7] (also known as the aspect compiler) Compile the modularized two types of concerns to construct a new system. In traditional development technology, the concept of cross-cutting concerns is not emphasized, so that objective cross-cutting requirements are forced to be implemented in the Code with core requirements, leading to confusion and decentralization of code. Therefore, how to separate the cross-cutting concerns from the core requirement module becomes the primary task of Aspect-Oriented technology [10].
2.2 Basic concepts of AOP
In Object-Oriented Programming (OOP), classes, objects, encapsulation, inheritance, polymorphism, and other concepts are the main terms used to describe object-oriented ideas. Similarly, some basic concepts exist in Aspect-Oriented Programming.
2.2.1 concerns
Concern: A focus can be a specific problem, concept, or application domain. In short, an application must achieve a goal. The focus is divided into the core focus and the cross-cutting focus. The core concern is the business logic, such as generating payroll, allowing employees to record and transfer funds to banks. For the definition of cross-cutting concerns, see 2.2.2 cross-cutting concerns.
2.2.2 cross-cutting concerns
Crosscutting concerns: concern is a specific purpose. It is a region we are interested in. From a technical point of view, A typical software system can be mapped to some core and system concerns. For example, the core focus of a credit card system is lending/deposit processing, while the system focus is on logs, transaction processing, authorization, security, and performance, they will appear in multiple modules. We call them cross-cutting concerns. The crosstab concern will appear in multiple modules. If the existing programming method is used, the cross-cutting concerns will jump across multiple modules, making it difficult for the system to design, understand, implement, and evolve. Compared with the preceding method, AOP can better isolate system concerns and provide modular cross-cutting concerns.
2.2.3 connection point
Joint point: Specifies a point during program execution. For example, when a method is called or an exception is handled, the following point is used to cut the application. The connection point can be a method call, constructor call, exception handling program, or other points in program execution. A join point is one of the core concepts of AOP. It is used to define where the program joins new logic through AOP. In Spring AOP, a connection point always indicates the execution of a method.
2.2.4 entry point
Pointcut: A pointcut is used to define a set of links for a notification to be executed at that time. By defining the entry point, We can precisely control the components in the program to receive notifications. As mentioned above, a typical connection node is a method call, and a typical starting point is a set of calls to the method where a class is located. We usually set up a complex entry point to control when the notification is executed. A notification is associated with an entry expression and runs on the connection point that meets the entry expression (for example, when a method with a specific name is executed ). How the entry point expression matches the connection point is the core of AOP: Spring uses the aspectj entry point syntax by default.
2.2.5 notification
Advice: a notification is one of the main program structures in the AOP language. It is usually associated with a certain starting point to describe the program logic to be called at the corresponding connection point, its structure is similar to the method in OOP ). In fact, in many AOP languages, notifications are stored and called as methods. The main difference is that when calling a method, you need to explicitly write the call statement in the basic program;
The Call Notification reflects the Hollywood law emphasized in AOP (Hollywood princple does not need to explicitly call the notification in the code of the basic program, the Calling logic is automatically inserted into the execution process of the basic program. In this way, developers do not need to consider the existence of notifications when writing basic programs, so they can focus more on business logic [14]. The types of basic notifications are as follows:
Before advice: A notification executed before a connection point. However, this notification cannot prevent the execution process before the connection point (unless it throws an exception ).
After returning advice: a notification that is executed after a connection point is completed normally. For example, a method does not throw any exception and returns a normal result.
After throwing advice: the notification that is executed when the method throws an exception and exits.
After (finally) Advice: the notification that is executed when a connection point exits (whether it is normal or abnormal ).
Discovery surround notification (around advice): notifications that enclose a connection point, such as method calls. This is the most powerful notification type. Surround notifications can complete custom actions before and after method calls. It will also choose whether to continue executing the connection point or directly return its own return value or throw an exception to end the execution.
2.2.6 Section
Aspect (aspect, also translated): the modularity of a focus, which may cross multiple objects and its position is equivalent to the class in OOP, which will notify, A combination of connection points and inter-type declarations. Similar to others, you can also have your own member functions and variables to expand and implement interfaces from other classes or aspects. Different from the class, the aspect structure is constructed by the AOP framework. The New Keyword cannot be used to explicitly generate an instance like a class [11].
In an abstract sense, the aspect is a certain attribute that has a certain impact on the performance and syntax of system components [12]. In design, it is a concern of some software systems for cross-cutting systems; implementation. A plane is a program constructor. It can encapsulate the concerns of the cross-cutting system into a single module Unit [13]. Typical sections include Exception Handling, log processing, security verification, transaction processing, and other modules.
2.2.7 goals
Target: a target is a place to be cut in. It is generally a core concern and business function. For example, in 2.2.2 cross-cutting concerns, the core focus of the credit card system is lending/deposit processing.
2.2.8 target object
Target object: The object notified by one or more slices. It is also called an advised object, that is, the object that is woven into the cross-concern, that is, this object is the object selected by the start point. It will be modified by a certain AOP during execution. For example, Spring AOP is implemented through runtime, and this object is always a proxied object.
2.2.9 knitting
Weaving: Create a notification object for assembling a plane [2]. Weaving is the process of actually adding the aspect to the program code. This can be completed during compilation (for example, using the aspectj compiler) or at runtime. Like other pure Java AOP frameworks, spring completes weaving during runtime.
2.3 cross-cutting
Cross-cutting is the key technology of AOP, that is, the core of AOP. This is also the difference between formal AOP and OOP. A system can be divided into objects (for example, inheritance) vertically from the perspective of P ). AOP separates a part of the system from a "horizontal" perspective. "Cross-cutting" is a special term of AOP. It is a relatively simple design and programming technology with powerful power. Especially when creating loosely coupled, scalable enterprise systems. Cross-cutting allows AOP to traverse the operations of the established responsibilities in a given programming model. If no cross-cutting technology is used. What is the situation of software development? In traditional programs, the implementation of cross-cutting behaviors is scattered. It is difficult for developers to implement or modify these behaviors logically. For example, the code used for logging and the Code primarily used for other duties are intertwined. Depending on the complexity and scope of the problem to be solved. The confusion may be big or small. Changing the logging policy for an application may involve hundreds of edits, even if feasible. This is also a headache task [15].
2.4 focus Recognition
In a complex system, it is composed of multiple concerns, such as business logic, performance, data storage, log and scheduling information, authorization, security, thread, and error check. 2.1 A group of concerns implemented by different modules constitute a system.

Figure 2.1 system composed of a group of concerns implemented by different modules
By identifying system requirements and implementation, we can divide these concerns in the module into core concerns and cross-cutting concerns. For core concerns, the modules that implement these concerns are independent of each other. They fulfill the business logic required by the system, which is related to specific business needs. But for the log, security, persistence and other concerns, they are the common needs of the business logic module, these logics are distributed in the core focus. In AOP, such modules are called cross-cutting concerns. The key to applying the cross-cutting technology of AOP is to recognize the concerns.
If the entire module is compared to a cylinder, the focus recognition process can be described by the prism rule. The beam passing through the prism (as required) can be illuminated everywhere in the cylinder to obtain different colors of the beam, at last, different concerns are identified. 2.2 focus recognition-Mitsubishi mirror Law

Figure 2.2 focus recognition-Mitsubishi mirror Law
Among the identified concerns, business logic is the core concern. It calls security, logging, persistence, and other cross-cutting concerns.
2.5 resolve cross-cutting concerns to core concerns
The purpose of AOP is to separate cross-cutting concerns such as logging from the businesslogic class. With AOP technology, you can encapsulate related cross-cutting concerns to form a separate aspect. This ensures the reuse of cross-cutting concerns. Because the businesslogic class no longer contains the logic code of the Cross-concern, to call the cross-concern, you can use the cross-concern technology to intercept messages of relevant methods in the businesslogic class, such as the someoperation () method, then, the cut planes are woven into the method. The cross-cutting focus is woven into the core focus, and the 2.3 AOP Model

Figure 2.3 AOP Model
By using the AOP technology, the design of the entire system is changed. At the beginning of analyzing system requirements, the idea of AOP is used to separate core points of concern and cross-cutting concerns. After implementing the general logic of cross-concern such as logs, transaction management, and permission control, developers can focus on their core concerns and focus on solving their business logic. At the same time, the functions provided by these encapsulated cross-cutting concerns can be used to restore all parts of the business logic to the maximum extent, without the need for special coding by developers, it also does not affect the specific business functions because of the function of modifying the cross-concern.

[1] lanhongyuan, lan Hong-yuan. Aspect-oriented programming methods [Journal Papers]-computer knowledge and technology (Academic Exchange) 2007,2 (9)
[2] He Qing and. Research on AOP programming ideology-software guide Journal, (3)
[3] Wei. Research and Application of the inverse method of Aspect-Oriented Programming [dissertation] 2008
[4] xingjun. Research and Application of AOP development process [dissertation] 2007
[5] Jin wangzheng, Li Ying, Xu jianghao, Li gansheng, Jin wangzheng, Li Ying, Xu jianghao, Li gansheng. research on Aspect-Oriented Programming Technology [Journal Papers]-computer applications and software (8)
[6] gang, Shuo, Hu Zhi-gang, ni Shuo. Aspect-Oriented Programming and its implementation technologies [Journal Papers]-computer engineering and design (8)
[7] Guo Dongliang, Zhang lichen, Guo Dong-liang, and Zhang Li-Chen. Research on Aspect-Oriented Software Development [Journal Papers]-Computer Application Research (8)
[8] Deng A-Qun, Li Xiaojun, Yu huanjun, Hu shangpo. Research on a New software design method AOP [journal paper]-system engineering and electronic technology (7)
[9] Lin Yun, Lin Yun. Research Based on Aspect-oriented programming methods [Journal Papers]-computer knowledge and technology (8)
[10] Song Xiaopeng, Sheng Zhongyi, Pan hongxia, and Bai Xiaofeng. Research on Aspect-oriented programming methods [journal paper]-Microcomputer Information 2006 (12)
[11] Wei zhenyuan. Research and Discussion Based on AOP technology. Application Science. 2008 (15)
[12] Zhang qianxi, Wang huaimin. Research and Implementation of Software running track capture technology based on AOP [journal paper]-computer application 2008 (5)
[13] Zhang qianxi, Guo Changguo, Yuan hongliang, and Wang huaimin. research and Implementation of a General thread Monitoring Platform Based on AOP technology [Journal Papers]-computer engineering and science 2007 (5)
[14] Tang zuyu, Peng Zhiyong, Tang zukai, Peng Zhiyong. A summary of research on Aspect-Oriented Programming Languages. Computer science and exploration. 2010,4 (1)
[15] LV hangfei. Analysis of AOP programming technology. computer knowledge and technology (Academic Exchange). 2007,4 (21)
[16] Huang Lei on AOP and OOP, computer knowledge and technology (Academic Exchange), (20)
[17] Wang shenyuan, Dong Chuanliang, Liu yingdan. Research and Implementation of Aspect-Oriented Programming. Computer Application Research (11)
[18] ramnivas laddad I want my AOP !. (Part1 ~ Part3)
[19] yuan Xufeng. AOP Programming Based on Spring wide false. Computer and modernization. 2006 (1)
[20] Tang zuyu, Peng Zhiyong, Tang zukai, and Peng Zhiyong. A summary of research on Aspect-Oriented Programming Languages. Computer science and exploration, (1)
[21] Wang xuesong, Chen Zhan, Tang xuefei. Research on AOP and its Weaving Technology. Fujian computer 2006 (3)

AOP technology research-AOP Overview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.