Aspect Oriented Programming

Source: Internet
Author: User
Tags aop exception handling python decorator in python

So far aspect oriented programming has been well known to developers, whose shorthand AOP is translated into aspect-oriented programming (also known as facet programming). It originated in the 90 's Xerox PARC Laboratory programming paradigm. Known as the continuation of OOP, OOP focuses on the domain problems of the business process, forming domain objects and better describing the natural domain. While AOP mainly deals with the separation of logical steps in the business process and reduces the coupling of business logic, it is our developers who only care about the core practical logic of the domain during the development process. Soc (separation of concerns) is presented in structured programming (SP), and has been described as one of the most effective approaches to complex software, and is being applied to different software practices, such as presentation layer pattern MVC,MVP,PM, SOA for service-oriented programming, abstraction programming, etc. AOP is the application of SOC, the separation of business logic step flow in the domain, yes we can only care about our real domain core business. Personally, AOP is a remedy for OOP, not an innovation.

The implementation of AOP in my essay IOC/AOP essay catalogue mentioned, mainly divided into static and dynamic injection two ways, the main difference is in different code period, compile time and run-time. In fact, there are some common frameworks for implementation in 3rd, such as the actionfilter in asp.net mvc, Handler, which is usually fixed by the template method, releasing the main logic to be implemented.

AOP consists of two important components: 1 matching rules, in the common AOP framework implementation, there are methods, classes, assemblies, package names or fixed features to exact match or fuzzy matching, the most common simple annotation Java Annocaton,. NET attribute. 2hack logic. For AOP is the hack of method boundaries, a method for us has 3 visible boundaries, entry, end, and exception. AOP is to insert hack logic in these 3 boundaries to realize the separation of common business.

AOP application scenarios: In the cache, log, exception handling, complex permissions, transactions, performance counts and so on have a common common process sequence is the logic for its main feature of the scene.

The following is an introduction to AOP implementations in the centralized language I am familiar with:

1:python

Implementing AOP in Python will be the simplest, thinking that decorating functions in Python is a natural AOP,

Def aoplogic (f):

def Warp ():

Print ("befor ...")

f ();

Print ("After ...")

return warp

@aopLogic

Def myMethod ():

Print ("My Method pass!")

Def myMethod1 ():

Print ("My Method pass!")

MyMethod ()

Print ("---------------------")

Aoplogic (MYMETHOD1) ()

Print ("---------------------")

Input ("Finish ...")

Output:

The Python decorator function starts with a @, followed by any function. Above is a parameterless AOP demo, we can see the decorated MyMethod = Aoplogic (MyMethod (no decoration)). If the decorated function for the parameter is, Aoplogic (args. ) (MyMethod (no decoration)).

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.