Introduction to functions and implementations of Aspect-Oriented Programming

Source: Internet
Author: User
1. Why is cross-section-oriented programming?

Aspect-oriented programming (AOP is the abbreviation of Aspect Oriented Program)We know that object-oriented features inheritance, polymorphism, and encapsulation. Encapsulation requires that functions be distributed to different objects, which is often called Responsibility Assignment in software design. In fact, let different classes design different methods. This wayCodeIt is dispersed into classes. This reduces the complexity of the code and makes the class reusable.

However, it is also found that code duplication is also increased while code is scattered. What does it mean? For example, we may need to log in every method in two classes. Based on the object-oriented design method, we must add the log content to the methods of both classes. Maybe they are exactly the same, but it is because the object-oriented design makes the Class and Class unable to be linked, rather than unifying the repeated code.

Some people may say that it is easy to do. We can write this code in an independent class independent method and then call it in these two classes. However, in this way, these two classes are coupled with the independent classes we mentioned above, and their changes will affect these two classes. Is there any way to add code as needed? During the runtime, the idea of dynamically cutting the code into the specified method and position of the class is the Aspect-Oriented Programming.

Implementation of Aspect-Oriented Programming

generally, it is called a cut-in to the code segment of the specified method of the specified class, and the cut-in class and method are called the cut-in point. With AOP, we can extract the code of several classes into a single slice, and then cut into the object when necessary to change its original behavior.
in this case, AOP is actually just a supplement to OOP. Oop separates classes horizontally, while AOP adds specific code to objects vertically. With AOP, oop becomes three-dimensional. With the time dimension added, AOP changes Oop from the original two-dimensional to the three-dimensional, from the plane to the three-dimensional. technically, AOP is basically implemented through the proxy mechanism.
AOP is a milestone in programming history and is a useful supplement to OOP programming.

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.