一、

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. C#3.0 LINQ 操作符

    Table 类: public class DemoDataContext : DataContext { public DemoDataContext (string cxString) : bas ...

  2. linux下设置mysql数据库字符集utf8

    mysql中文乱码解决方法:将mysql数据库编码统一utf8 查看数据库编码: show variables like 'character%'; 编辑/etc/my.cnf [mysql] def ...

  3. 深入理解java的抽象类和接口(转载)

    原文链接:http://www.cnblogs.com/dolphin0520/p/3811437.html 对于面向对象编程来说,抽象是它的一大特征之一.在Java中,可以通过两种形式来体现OOP的 ...

  4. SQLSERVER2000使用TSQL将数据导入ACCESS并压缩生成rar

    查询分析器操作ACCESS数据表数据 (1)查询:select top 10 * from OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'C:\Documents an ...

  5. Scala语言初识

    scala是一种集面向对象特性和函数式特性于一身并可运行在JVM上的强类型静态语言.因为可以运行在JVM上,并在设计时借鉴于大量的java语言特性,故可以和java互动并可以调用java相关类库,这让 ...

  6. 20个linux命令行工具监视性能(上)

    对于每一个系统管理员或网络管理员每天监视或调试linux系统的性能问题是一件非常困难的事,在it行业作为一个linux管理员五年之后,我开始知道监视和保持系统启动和运行有多么的困难.由于这个原因,我们 ...

  7. ###再探Makefile

    使用makefile.以前刚开始接触Makefile的时候,写过一个最简单的Makefile.点击查看Evernote原文. #@author: gr #@date: 2014-07-20 #@ema ...

  8. 关于Encoding.GetEncoding("utf-8")和Encoding.GetEncoding("GB2312")及Encoding.Default

    关于Encoding.GetEncoding("utf-8")和Encoding.GetEncoding("GB2312")及Encoding.Default ...

  9. [Guava官方文档翻译] 2.使用和避免使用null (Using And Avoiding Null Explained)

    本文地址:http://www.cnblogs.com/hamhog/p/3536647.html "null很恶心." -Doug Lea "这是一个令我追悔莫及的错误 ...

  10. OpenJudge 2795 金银岛

    1.链接地址: http://bailian.openjudge.cn/practice/2795/ 2.题目: 总Time Limit: 3000ms Memory Limit: 65536kB D ...