一、

Aspect就是把会在应用中的不同地方重复出现的非业务功能的模块化,比如日志、事务、安全、缓存

In software development, functions that span multiple points of an application are
called cross-cutting concerns. Typically, these cross-cutting concerns are conceptually
separate from (but often embedded directly within) the application’s business logic.
Separating these cross-cutting concerns from the business logic is where aspect-
oriented programming ( AOP ) goes to work.

DI helps you decouple application objects from
each other, AOP helps you decouple cross-cutting concerns from the objects they
affect.
Logging is a common example of the application of aspects, but it’s not the only
thing aspects are good for. Throughout this book, you’ll see several practical applica-
tions of aspects, including declarative transactions, security, and caching.

aspects help to modularize cross-cutting concerns. In short, a cross-
cutting concern can be described as any functionality that affects multiple points of an
application. Security, for example, is a cross-cutting concern, in that many methods in
an application can have security rules applied to them. Figure 4.1 gives a visual depic-
tion of cross-cutting concerns.
This figure represents a typical application that’s broken down into modules.
Each module’s main concern is to provide services for its particular domain. But each
module also requires similar ancillary functionality, such as security and transaction
management.

A common object-oriented technique
for reusing common functionality is to
apply inheritance or delegation. But inheri-
tance can lead to a brittle object hierarchy
if the same base class is used throughout an
application, and delegation can be cumber-
some because complicated calls to the dele-
gate object may be required.
Aspects offer an alternative to inheri-
tance and delegation that can be cleaner in
many circumstances. With AOP , you still
define the common functionality in one
place, but you can declaratively define how and where this functionality is applied
without having to modify the class to which you’re applying the new feature. Cross-
cutting concerns can now be modularized into special classes called aspects. This has
two benefits. First, the logic for each concern is in one place, as opposed to being scat-
tered all over the code base. Second, your service modules are cleaner because they
only contain code for their primary concern (or core functionality), and secondary
concerns have been moved to aspects.

SPRING IN ACTION 第4版笔记-第四章Aspect-oriented Spring-001-什么是AOP的更多相关文章

  1. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-010-Introduction为类增加新方法@DeclareParents、<aop:declare-parents>

    一. 1.Introduction的作用是给类动态的增加方法 When Spring discovers a bean annotated with @Aspect , it will automat ...

  2. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-003-Spring对AOP支持情况的介绍

    一. 不同的Aop框架在支持aspect何时.如何织入到目标中是不一样的.如AspectJ和Jboss支持在构造函数和field被修改时织入,但spring不支持,spring只支持一般method的 ...

  3. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-005-定义切面使用@Aspect、@EnableAspectJAutoProxy、<aop:aspectj-autoproxy>

    一. 假设有如下情况,有一个演凑者和一批观众,要实现在演凑者的演凑方法前织入观众的"坐下"."关手机方法",在演凑结束后,如果成功,则织入观众"鼓掌& ...

  4. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-004-使用AspectJ’s pointcut expression language定义Pointcut

    一. 1.在Spring中,pointcut是通过AspectJ’s pointcut expression language来定义的,但spring只支持它的一部分,如果超出范围就会报Illegal ...

  5. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-002-AOP术语解析

    一. 1.Advice Advice是切面的要做的操作,它定义了what.when(什么时候要做什么事) aspects have a purpose—a job they’re meant to d ...

  6. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-012-AOP总结

    1.AOP是面向对象编程的有力补充,它可以让你把分散在应用中的公共辅助功能抽取成模块,以灵活配置,减少了重复代码,让类更关注于自身的功能

  7. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-011-注入AspectJ Aspect

    一. 1. package concert; public interface CriticismEngine { public String getCriticism(); } 2. package ...

  8. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-009-带参数的ADVICE2 配置文件为XML

    一. 1.配置文件为xml时则切面类不用写aop的anotation package com.springinaction.springidol; public class Magician impl ...

  9. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-009-带参数的ADVICE2

    一. 情景:有个魔术师会读心术,常人一想一事物他就能读到.以魔术师为切面织入常人的内心. 二. 1. // <start id="mindreader_java" /> ...

  10. SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-008-带参数的ADVICE

    一. 假设有情形如:cd里有很多轨,当播放音乐时,要统计每个音轨的播放次数,这些统计操作不应放在播放方法里,因为统计不是播放音乐的主要职责,这种情况适合应用AOP. 二. 1. package sou ...

随机推荐

  1. asp下实现多条件模糊查询SQL语句

    常写一个简单的模糊查询的SQL语句格式可以如下例: sql="select * from 表名 where 字段名 like ’%" & request.form(&quo ...

  2. Sqlserver 理解子查询

    理解子查询: 理解子查询: 多表连接查询往往也可以用子查询进行替代 子查询本质是嵌套进其他 select update insert Delete 语句的一个被限制的select语句,在子查询中,只有 ...

  3. linux配置学习笔记(一):如何提高ssh连接的速度

    服务器端sshd配置文件 /etc/ssh/sshd_config 看是否有如下的两条配置条目 GSSAPIAuthentication no UseDNS no 如果前面带#,请把#删掉,或者新添加 ...

  4. Java _Map接口的使用(转载)

    转载自:http://blog.csdn.net/tomholmes7/article/details/2663379.转载请注明原作者地址 Map Map以按键/数值对的形式存储数据,和数组非常相似 ...

  5. iOS推送通知流程

    ①注册推送通知使用方法:registerUserNotificationSettings, registerForRemoteNotifications ④APP发送deviceToken到第三方: ...

  6. 使用jQuery调用ASP.NET WebService的简易教程

    鉴于使用Javascript调用Web Service配置略麻烦,所以记录一下. 1. 新建一个Web服务(WebService.asmx) 2. 取消注释// [System.Web.Script. ...

  7. JS代码大全 (都是网上看到 自己整理的)

    事件源对象  event.srcElement.tagName  event.srcElement.type 捕获释放  event.srcElement.setCapture();   event. ...

  8. 07_XPath_02_常用语法

    [工程截图] [person.xml] <?xml version="1.0" encoding="UTF-8"?> <students> ...

  9. 学习C++ Primer 的个人理解(十二)

    动态内存与智能指针 在C++中, 动态内存用 new来分配空间并返回一个指向该对象的指针 用delete来销毁. 由于手动的对动态内存进行操作容易出现问题.所以新的标准库提供了两种智能指针. 智能指针 ...

  10. linux 配置Socks5

    1.配置 Socks5 编译环境. yum -y install gcc automake autoconf libtool make 2.安装 Socks5 需要的包. yum -y install ...