AOP programming paradiag
AOP
https://en.wikipedia.org/wiki/Aspect-oriented_programming
Typically, an aspect is 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 use 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 are expressed but also with each other. That means changing one concern entails understanding all the tangled concerns or having 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,面向切面的编程),它是可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术。它是一种新的方法论,它是对传统OOP编程的一种补充。
OOP是关注将需求功能划分为不同的并且相对独立,封装良好的类,并让它们有着属于自己的行为,依靠继承和多态等来定义彼此的关系;AOP是希望能够将通用需求功能从不相关的类当中分离出来,能够使得很多类共享一个行为,一旦发生变化,不必修改很多类,而只需要修改这个行为即可。
Lua AOP
http://lua.2524044.n2.nabble.com/Question-about-AOP-like-function-calls-interception-td7651107.html
The reason why I'm asking is to see how something like AOP (Aspect Oriented Programming) approach could be 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 what I want to intercept (e.g. using patterns like this: "all calls of functions that look like set* or libname.*") outside of the code, where interception is supposed to be applied. That is the source code should not be aware of interception if possible. Normally it is achieved by means of interception or instrumentation in most languages. I'm wondering how and if this can be done in Lua.
local _print = print print = function( … )
-- before...
_print( … )
-- after...
end
http://lua-users.org/lists/lua-l/2011-01/msg00187.html
as many things OO, most 'fun' things in aspects are trivial to do in
functional programming: for example, it's common to enhance the built-on type() function: do
local oldtype = type
function type(x)
local mt = getmetatable(x)
if mt and mt.__type then return mt.__type end
return oldtype(x)
end
end or you could do some 'prepend' functions: function prepend(f,pre)
return function(...)
return pre(f,...)
end
end and use like this: type = prepend (type, function(old, x)
local mt = getmetatable(x)
if mt and mt.__type then return mt.__type end
return old(x)
end
AOP lua库
http://luaforge.net/projects/aspectlua/
AspectLua is an 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 written in pure Lua.
如下: 对account 的 deposit方法进行跟踪, 调用完后, 进行打印。
dofile("AspectLua.lua") account = luaorb.createproxy(readIOR("account.ref"),"IDL:Account:1.0")
account:deposit() function logfile(a)
print("o valor depositado e",a)
end asp = Aspect:new("aspect.ref")
asp:aspect({name = 'AccountLogging'} , {name = 'tracingMethods', designator = 'call', list = {'bank_impl.deposit'}}, {type ='after', action = logfile})
AOP programming paradiag的更多相关文章
- 在.NET Core中三种实现“可插拔”AOP编程方式(附源码)
一看标题肯定会联想到使用动态编织的方式实现AOP编程,不过这不是作者本文讨论的重点. 本文讨论另外三种在netcore中可实现的方式,Filter(过滤器,严格意义上它算是AOP方式),Dynamic ...
- 热修复 DexPosed AOP Xposed MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- Jerry的Fiori原创文章合集
我曾经于2014年10月到2016年5月工作于SAP CRM Fiori应用的开发团队, 我所在的团队负责下列这8个Fiori应用的维护和持续开发: My Opportunities My Tasks ...
- dexposed框架Android在线热修复
移动client应用相对于Webapp的最大一个问题每次出现bug,不能像web一样在server就完毕修复,不须要发版本号.紧急或者有安全漏洞的问题, 假设是Webapp你可能最多花个1,2个小时紧 ...
- 关于面向切面编程Aspect Oriented Programming(AOP)
最近学到spring ,出来了一个新概念,面向切面编程,下面做个笔记,引自百度百科. Aspect Oriented Programming(AOP),面向切面编程,是一个比较热门的话题.AOP主要实 ...
- Aspect Oriented Programming using Interceptors within Castle Windsor and ABP Framework AOP
http://www.codeproject.com/Articles/1080517/Aspect-Oriented-Programming-using-Interceptors-wit Downl ...
- Spring面向切面编程(AOP,Aspect Oriented Programming)
AOP为Aspect Oriented Programming的缩写,意为:面向切面编程(也叫面向方面),可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
- Java实战之03Spring-03Spring的核心之AOP(Aspect Oriented Programming 面向切面编程)
三.Spring的核心之AOP(Aspect Oriented Programming 面向切面编程) 1.AOP概念及原理 1.1.什么是AOP OOP:Object Oriented Progra ...
- AOP Aspect Oriented Programming
原理AOP(Aspect Oriented Programming),也就是面向方面编程的技术.AOP基于IoC基础,是对OOP的有益补充. AOP将应用系统分为两部分,核心业务逻辑(Core bus ...
随机推荐
- 【转载】科研ppt制作的体会
转载自实验室陈家雷学长发在bbs 上的帖子,讲解了自己制作ppt的心得体会.学习下. 附件中是我昨天晚上我的组会ppt的pdf版本,另外我对ppt的制作有点自己的理解,基本上都是去年暑假在Harvar ...
- (iOS) __block和__weak认识
果然还是对最基础的知识了解不透彻,今天看一看iOS中的两个修饰符:__block和__weak .也是做一下温习吧. 1.先说weak,<弱引用> 我们知道weak的使用,比如声明一个控件 ...
- 集中式vs分布式区别
记录一下我了解到的版本控制系统,集中式与分布式,它们之间的区别做下个人总结. 什么是集中式? 集中式开发:是将项目集中存放在中央服务器中,在工作的时候,大家只在自己电脑上操作,从同一个地方下载最新版本 ...
- 洛谷 P2735 电网 Electric Fences Label:计算几何--皮克定理
题目描述 在本题中,格点是指横纵坐标皆为整数的点. 为了圈养他的牛,农夫约翰(Farmer John)建造了一个三角形的电网.他从原点(0,0)牵出一根通电的电线,连接格点(n,m)(0<=n& ...
- Apache虚拟主机配置,实现多域名访问本地项目PHP空间,以及配置403Forbidden等错误的解决办法
第一步: apache主配置文件修改: 用文本编辑器打开apache的conf目录下 httpd.conf 将下面以下代码取消注释 LoadModule rewrite_module modules ...
- NOIP2012拓展欧几里得
拉板题,,,不说话 我之前是不是说过数据结构很烦,,,我想收回,,,今天开始的数论还要恶心,一早上听得头都晕了 先来一发欧几里得拓展裸 #include <cstdio> void gcd ...
- Query Mobile学习笔记
1.获取jQuery mobile 文件,访问jQuerymobile网站下载 (貌似使用jquery mobile后,jquery会自动在网页中添加一些class类,第一次知道的我是被吓呆的!!) ...
- Delphi中字符串补齐方法
函数功能:当Str不满Len长度时,在Str前自动填充PadStr以补足长度,例子如下: Str:原字符串 Len:补多长 PadStr:用什么补齐,比如‘0’ function PadString( ...
- bzoj 3438: 小M的作物
Description 背景 小M还是个特么喜欢玩MC的孩纸... 描述 小M在MC里开辟了两块巨大的耕地A和B(你可以认为容量是无穷),现在,小P有n中作物的种子,每种作物的种子有1个(就是可以种一 ...
- C %p
格式控制符“%p”中的p是pointer(指针)的缩写.指针的值是语言实现(编译程序)相关的,但几乎所有实现中,指针的值都是一个表示地址空间中某个存储器单元的整数.printf函数族中对于%p一般以十 ...