AOP Programming Paradiag

Source: Internet
Author: User

Aop

Https://en.wikipedia.org/wiki/Aspect-oriented_programming

Typically, an aspect are scattered or tangled as code, making it harder to understand and maintain. It is scattered by virtue of the function (such as logging) being spread over a number of unrelated functions that might u SE Its function, possibly in entirely unrelated systems, different source languages, etc. That means to change logging can require modifying all affected modules. Aspects become tangled not only with the mainline function of the systems in which they is expressed but also with each O Ther. That means changing one concern entails understanding all the tangled concerns or have some means by which the effect of Changes can be inferred.

Logging exemplifies a crosscutting concern because a Logging strategy necessarily affects every logged part of the system. Logging thereby crosscuts all logged classes and methods.

Http://www.cnblogs.com/beliefbetrayal/archive/2012/02/03/2337522.html

  AOP (aspect-oriented programming, aspect-oriented programming), is a technology that can dynamically and uniformly add functionality to a program without modifying the source code, through precompilation and runtime dynamic proxy implementations. It is a new methodology that complements traditional OOP programming.

OOP is concerned with dividing the requirements function into different and relatively independent, well-encapsulated classes, and letting them have their own behavior, relying on inheritance and polymorphism to define each other's relationships; AOP is the ability to separate common requirements functions from unrelated classes, enabling many classes to share a single behavior, once changed , you do not have to modify many classes, but you only need to modify this behavior.

Lua AOP

Http://lua.2524044.n2.nabble.com/Question-about-AOP-like-function-calls-interception-td7651107.html

The reason why I ' m asking are to see what something like AOP (Aspect oriented programming) approach could was applied to Lua. For example, I-d like-to-be-able to-execute a custom code before or after-a call, manipulate-call arguments and results, etc. And I ' d like-to-be-able to specify-I want to intercept (e.g. using-patterns like this: "All calls of the functions that L Ook like set* or libname.* ") outside of the code, where interception was supposed to be applied. That's the source code should not being aware of interception if possible. Normally it is achieved by means of interception or instrumentation in the most languages. I ' m wondering how and if this can is done in Lua.


Local_printprintprintfunction(...) -- before ... _print (...) -- After ... End

Http://lua-users.org/lists/lua-l/2011-01/msg00187.html

As many things OO, most' Fun'ThingsinchAspects is trivial to Do inchFunctional Programming: forexample, it's common to enhance the built-on type () function: Do  LocalOldtype =type  function type(x)LocalMT =getmetatable(x)ifMt andMt.__type Then returnMt.__typeEnd    returnoldtype (x)EndEndorYou could DoSome'prepend'functions:functionprepend (F,pre)return function(...) returnpre (F,...) EndEnd andUse the like this :type= Prepend (type,function(old, x)LocalMT =getmetatable(x)ifMt andMt.__type Then returnMt.__typeEnd  returnOld (x)End

AOP Lua Library

http://luaforge.net/projects/aspectlua/

Aspectlua is a extension of Lua for aspect-oriented programming. It follows some concepts of AspectJ, and enables the creation of aspects for Modularize crosscutting concerns in objects W Ritten in pure Lua.

As follows: The deposit method of account is tracked, and after the call is finished, it is printed.

Dofile("Aspectlua.lua") Account= Luaorb.createproxy (Readior ("Account.ref"),"idl:account:1.0") Account:deposit (5)functionlogfile (a)Print("o Valor depositado e", a)EndASP= Aspect:new ("Aspect.ref") asp:aspect ({name='accountlogging'}, {name ='Tracingmethods', designator ='Pager', List = {'Bank_impl.deposit'}}, {type=' After', action = logfile})

AOP Programming Paradiag

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.