Introduction to Aspect-Oriented Programming-basic concepts (1)

Source: Internet
Author: User
Tags introductions

Introduction to Aspect-Oriented Programming-basic concepts (1)

 

The common concepts of object-oriented programming are inheritance, encapsulation, and polymorphism. The following concepts are often used in Aspect-Oriented Programming: advices/interceptors, introductions, metadata, and pointcuts.

AOPIntroduction to Aspect-Oriented Programming----Basic concepts (3)

The Aspect-Oriented Programming idea is very simple. SlaveProcess-oriented and function-orientedProgrammingObject-orientedProgrammingInterface-orientedProgrammingComponents and modulesThe development history of programming we can know that the evolution of programming methodology expands the "boundary" of programming considerations step by step ". So far ourCosmic boundaries in the programming worldIt is a "class, interface, or component". In this boundary, we believe that one class can implement one interface dynamically, the behavior of existing classes is basically fixed before compilation. It is either a method defined inside the class, or a method inherited from the inheritance and implementation interfaces. However, in actual programming, we have encountered a "Cross-Boundary Situation", which requires multiple classes, interfaces, and components to work together, such as multi-thread concurrent access, centralized Control of program streams, serialization and program status maintenance, and the work that requires multiple "classes, interfaces, and component boundaries" to be completed. To better process multipleBoundaryAfter completing the same work, Aspect-Oriented Programming emerged. HereAspectTo complete the same task, we need to combine multiple classes, interfaces, and components for collaboration. You can think that the aspect is actually a larger class. This class is mainly composed of classes and interfaces in OOP. Of course, these classes and interfaces are so close that they act (methods) can be converted to each other. In fact, this is no big deal. Isn't the emergence of interfaces implementing dynamic changes to class behavior? Aspect-Oriented Programming is just an extension, which elevated the change to the interface level. Here, I feel: My ears are quiet, but the world is still not quiet, because it takes a long time to program with this idea, and support from more Tool developers.

In my subsequent articles, I want to unify the following concepts:
1. Inter-type declarations boundary internal type declaration: The Inter-type declaration has many forms in aspectj. It is used to describe the relationship between classes, the members and structure information of the classes.
2. Join point: the join point is a point defined in the program flow.
4. crosscutting concerns: consider border crossover
5. pointcuts connection point set: a set of states of multiple connection points held by the program running.
5. Advice notification point behavior: the connection point set is like a "structure" that contains multiple items and does not act itself. Its behavior is implemented by the notification point behavior.
The above terms are mainly used in the introduction of aspectj.

Advices/interceptors (Message Communication/message interception)

A "message" is the logic (CODE) triggered by a specific event ). This "transmitted message" can be inserted between a caller and the called queue. It can be said that message communication is a key component of Aspect-Oriented Programming.

Introductions (recommended by Members)

IntroductionsIs a method used to add methods and attributes to an existing class. We recommend that you "introduce" an existing class implementation interface to another new interface.As you know, interfaces are designed to separate definitions and implementations. Now, with Aspect-Oriented Programming, You can dynamically change existing class interfaces, which is incredible.Using "member recommendation" in Java programming, You can implement multiple inheritance for a Java class. That is to say, using "member recommendation", you can dynamically change the class interface while the program is running to implement different behaviors. Just like Sun Wukong can constantly change his behavior, but Sun Wukong must have three hairs (recommended by members "). See the following example:

Apple apple        = new Apple();

LoggingAPI logging = (LoggingAPI)apple;

Apple.setLoggingLevel(VERBOSE);

Use "Recommended members": Apple can dynamically own the log function.

Metadata)

Metadata is used to describe some additional information of the class and its description class. It can obtain the description information of these classes at static or re-running times. For example, see my other article (using the reflection mechanism to implement a dynamic factory model ). A large amount of metadata is used in EJB.

Pointcuts

If interceptors, introductions, and metadata are characteristic of Aspect-Oriented ProgrammingPointcutsAre is the glue that connects them together ". Pointcuts runs in the AOP framework. For example, it tells the framework how to confirm message communication, how metadata is defined in the class, and the classes and interfaces are "recommended by members.

Let's talk about the AOP framework in JBoss 4.0.

Http://www.onjava.com/pub/a/onjava/2003/05/28/aop_jboss.html

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.