Aspectj learning note [01]

xiaoxiao2021-03-06  40

Dynamic crosscutting

Dynamic transverse refers to inserting a new behavior when executed in a program. Most of the cross-cuts that occur in Aspectj are dynamic.

Static crosscutting

Static transverse refers to behavior for correcting the static structure of the program - such as the class, interface, aspect, etc. of the system. It cannot change the implementation of the system.

Element

Join Point

A connection point is a marking point in an application execution. It can be a method of call or allocation of a class of data. Such as:

Public class account {

...

Void Credit (Float Amount) {

_balance = Amount;

}

}

The connection point in the Account class includes the execution of the CRedit method and the access to the _balance instance member.

Pointcut

Subject is a program structure that selects some connection points and these connection points context. As we capture the execution of the Credit method in the Account class:

EXECUTION (Void Credit (Float))

ADVICE

The notification is the code to be executed by the connection point selected by a cut point. The notification can be performed in front of the connection point, after, a surrounding. The surrounding notice can change the execution of the code at the connection point, which can replace this code or bypass this code. Notification is similar to one way. With the previous cutting point, we can print a message before the Credit method of the Account class:

Before (): EXECUTIONG (Void Credit (Float) {

System.out.println ("About to Perform Credit Operation);

}

The cutting point and notice constitute a dynamic cross cut.

Introduction

Guide a static cross-cut instruction, which has introduced some changes to the system class, interface, and aspect. It performs static changes for some modules without affecting their actions. For example, you can add a method or field for a class.

Declare Parents: Account Implements BankingEntity;

Compile-Time Declaration

When compiling is a static cross-cutting directive, which allows you to add the warnings and error notifications you want under some of your specified sources. Such as:

Declare Warning: Call (Void Persistence.save (Object))

: "Consider Using Persistence.SaveOptimized ()";

Aspect

Aspect is the core unit in AspectJ, like the status of the class in Java. It contains expressions required for static transverse and dynamic cross cuts. Clearing points, notifications, guidance, strategies, and combinations thereof can be included in terms. In terms of aspects, data, methods, and nested class members can also be included, just like a normal Java class. Such as:

Public aspect examplepect {

Before (): execution (Void Account.credit (Float) {

System.out.println ("About to Perform Credit Operation);

}

Declare Parents: Account Implements BankingEntity;

Declare Warning: Call (Void Persistence.Save (Object)): "Consider Using Persistence.SaveOptimized ()";

转载请注明原文地址:https://www.9cbs.com/read-72163.html

New Post(0)