`
dearwolf
  • 浏览: 339522 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

AOP的一些基本概念

    博客分类:
  • AOP
阅读更多
先说一下AOSD的起源吧

传统的软件工程有一个不变的主题:对关注点的分解和局部化。将系统分解成为主要的功能模块,识别出关注点的其他问题,确保所有关注点的问题都能在代码的适当位置得到解决。但是关注点的分散和混杂又给代码编写和后期维护带来了很大的难度。
因此,必须有一种方法可以把关注点集中在一起,让系统开发者可以使用关注点自身的模块来描述每个关注点的行为。
AOSD,用以寻找软件系统中新的模块化特性,允许对系统中多个关注点进行独立描述,同时又能自动统一到系统中。

然后是一些常用的术语(from AOSD wiki):

concern(关注点):A concern is an area of interest or focus in a system. Concerns are the primary criteria for decomposing software into smaller, more manageable and comprehensible parts that have meaning to a software engineer.

crosscutting(横切):Note that crosscutting is a relationship between representations of concerns. Note also that it is a symmetric relationship. Therefore, if:

1. A is a representation of one a concern,
2. B is a representation of another concern, and
3. A crosscuts B,

then B also crosscuts A.

This means that the term "crosscutting concerns" is often misused in two ways: To talk about a single concern, and to talk about concerns rather than representations of concerns. Consider "synchronization is a crosscutting concern": we don't know that synchronization is crosscutting unless we know what it crosscuts. And there may be representations of the concerns involved that are not crosscutting.

aspect(方面):Aspects are one kind of concern in software development.

joint point(联接点):Join points are those elements of the programming language semantics which the aspects coordinate with. Nowadays, there are various join point models around and still new under development. They heavily depend on the underlying programming language and AO language.

In a number of presently available AOP languages, a join point is a region in the dynamic control flow of an application. Thus a join point can for instance represent

* a call to a method,
* execution of a method,
* the event of setting a field,
* the event of handling an exception ...

Join points can be picked up by an AOP program by using pointcuts to match on them. Depending on the pointcut language the AOP language provides, it may be possible to pick up more or less of those join points. Since join points are dynamic, it may be possible to expose runtime information such as the caller or callee of a method from a join point to a matching pointcut.

advice:In a number of AOP languages, advice consists of a pointcut and a body. The body executes at join points the pointcut matches. This pointcut may expose runtime information to the advice body.

pointcut:

(from Without EJB):A set of join points,defined to specify when an advice should fire.Pointcuts are often described using either regular expressions or another wildcard syntax.

(from Wiki)In a number of AOP languages, a pointcut is a predicate over dynamic join points, meaning that given a certain dynamic join point, a pointcut can either match this join point or not (at runtime). Another view of pointcuts is often, that they represent sets of join points. A pointcut may expose runtime information to a piece of advice.

Weaving:The process of coordinating aspects and non-aspects. Weaving can be done explicitly or implicitly, and can be done at a variety of times ranging from by-hand weaving when code is written, through compile-time, post-compile time and load time, up to runtime.

Without EJB中有个例子很好的解释了一下上面的术语:

public class MyBusinessObject implements BusinessObject{
public void businessMethod1() throws UnauthorizedException{
doSecurityCheck();
}
public void businessMethod2() throws UnauthorizedException{
doSecurityCheck();
}
public void requiresNoSecurityCheck() {
}
public void doSecurityCheck() throws UnauthorizedException{
}
}

这里,安全检查就是一个aspect,需要进行安全检查的这几个方法就是join point。而由于不是所有的方法都需要进行安全检查,所以就需要用pointcut来进行匹配。

下面使用了一个interceptor来将关注点模块化:

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class SecurityInterceptor implements MethodInterceptor{
public Object invoke(MethodInvocation invocation)throws Throwable{
doSecurityCheck();
return invocation.proceed();
}
public void doSecurityCheck{}
}

这里的interceptor就是advice
分享到:
评论

相关推荐

    面向方面编程的Aop介绍

    本教程介绍 AOP 及其基本概念。AOP 及其相关的工具使您可以将基本横切关注点(如日志记录和安全)的代码,与程序的核心应用逻辑相分离。AOP 通过使代码更具有可读性、更不容易出错以及更容易设计和维护,改善了代码...

    Spring AOP详细介绍.docx

    一 AOP的基本概念 (1)Aspect(切面):通常是一个类,里面可以定义切入点和通知 (2)JointPoint(连接点):程序执行过程中明确的点,一般是方法的调用 (3)Advice(通知):AOP在特定的切入点上执行的增强处理,有before,after...

    实验2 Spring AOP源码

    1、 理解Spring AOP原理和基本概念; 2、掌握基于XML/注解方式的AOP编程; 二:实验内容 1、 定义交易接口: public interface Transaction{ public void income(float amount);//收入 public void expenditure...

    新型软件开发方法AOP的研究.pdf

    本文首先介绍了AOP技术的产生背景和基本概念,提出了AOP概念模型和特 性模型,并且在特性模型中归纳了AOP编织的四个关键特性,然后据此对当前的典型AOP实现技术及 其优点进行了分析,最后展望了AOP技术未来的发展...

    spring介绍ppt 介绍spring的基本概念和使用

    spring介绍ppt 介绍spring的基本概念和使用,从ioc和aop讲起,对想快速了解spring的人有很大帮助

    论文研究-面向方面软件开发研究.pdf

    其次,阐述了AOP的基本概念,并结合AspectC 演示了如何进行面向方面的编程;再次,描述了如何对UML扩展以支持对方面建模;然后介绍了面向方面软件开发在实时系统中的应用;最后给出了结论和未来的主要工作。

    weaverl:Erlang 遇到 AOP

    基本概念 待定 入门 待定 免责声明:这个项目是作为一个练习开始的,目的是了解更多关于 Erlang/OTP 的解析转换。 不要期望一个成熟的、没有错误的工具可以集成到生产软件中,而是一个实验性的软件,你可以用它来...

    java视频教程:spring框架精讲附加实战项目练习

    主要讲Spring的核心概念和基本使用。涉及IoC、DI、AOP、JdbcTemplate和事务管理等核心概念。同时讲解了xml和注解两种方式使用Spring的示例。通过Spring的入门程序介绍了Spring的 IoC 和 DI 的概念,介绍了Spring的...

    论文研究-面向方面的权限管理研究 .pdf

    面向方面的权限管理研究,陈玉良,孟祥武,本文介绍了基于角色的访问控制理论RBAC和面向方面编程AOP的基本概念,并将二者结合用于系统权限管理。实践表明,该技术使业务逻辑��

    Spring概述

    Spring的一些基本概念的介绍,例如IoC,AOP等,并介绍了这么使用Spring

    JAVA面试常见问题整理

    最后,文章简要概述了Spring框架的基本概念和作用,包括IOC、AOP、Bean的作用域等内容。同时,还涉及了事务处理的并发问题、Spring事务的实现方式和隔离级别等相关知识。 总之,本文为读者提供了一个关于Java面试...

    java中的0 can‘t find referenced pointcut runTim

    Aop的一些常用基本概念 Advice(通知、切面): 某个连接点所采用的处理逻辑,也就是向连接点注入的代码, AOP在特定的切入点上执行的增强处理。 @Before: 标识一个前置增强方法,相当于BeforeAdvice的功能. @...

    面向方面编程和AspectJ一.pdf

    面向方面编程(AOP)的基本概念及其实现技AspectJ。用一个完整的、可运行的实例,详细说明AOP方法厦其具体应用。

    面向方面软件开发研究* (2005年)

    其次,阐述了AOP 的基本概念,并结合Aspect C ++ 演示了如何进行面向方面的编程;再次,描述了如何对UML 扩展以支持对方面建模;然后介绍了面向方面软件开发在实时系统中的应用;最后给出了结论和未来的主要工作。

    基于javaWeb实现计算机配件报价系统项目设计源码分享

    (1)基本概念 Spring是一个开源开发框架,是一个轻量级控制反转(IoC)和面向切面(AOP)的容器框架。 spring主要用来开发java应用,构建J2EE平台的web应用。其核心就是提供一种新的机制管理业务对象及其依赖关系 ...

    基于javaWeb实现计算机配件报价系统项目设计源码

    (1)基本概念 Spring是一个开源开发框架,是一个轻量级控制反转(IoC)和面向切面(AOP)的容器框架。 spring主要用来开发java应用,构建J2EE平台的web应用。其核心就是提供一种新的机制管理业务对象及其依赖关系 ...

    千锋JavaEE精讲之Spring框架实战教程

    涉及IoC、DI、AOP、JdbcTemplate和事务管理等核心概念。同时讲解了xml和注解两种方式使用Spring的示例。  通过Spring的入门程序介绍了Spring的IoC和DI的概念,介绍了Spring的基本模块。详细介绍了对象创建的...

    Spring.xmind

    Spring思维脑图详细介绍了spring的架构:ioc、aop、事务、基本概念。

    中软spring培训讲义

    Spring 基本概念(IOC);AOP;Spring 整合Struts,Hibernate

    2023Java高频面试题

    多线程编程:线程的基本概念、线程同步、线程安全、死锁等问题。 JDBC:Java与数据库的交互,连接池的使用等。 Spring框架:Spring框架的基础概念、IOC容器、AOP等。 Hibernate框架:Hibernate框架的基础概念、ORM...

Global site tag (gtag.js) - Google Analytics