下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、2020/8/14,Institute of Computer Software Nanjing University,1,Aspect Oriented Programming,面向方面的编程,2020/8/14,Institute of Computer Software Nanjing University,2,摘要,Background and Motivation AOP AspectJ Summary,2020/8/14,Institute of Computer Software Nanjing University,3,摘要,Background and Motivation
2、AOP AspectJ Summary,2020/8/14,Institute of Computer Software Nanjing University,4,Background and Motivation,Where OOP has brought us Reusability of components Modularity Less complex implementation Reduced cost of maintenance Modularity is a universal advancement over structured programming that lea
3、ds to clearer and better understood software,2020/8/14,Institute of Computer Software Nanjing University,5,Modularity in Reality,Code from org.apache.tomcat,XML Parsing,Red shows relevant lines of code,Nicely fits in one box,Good Modularity,2020/8/14,Institute of Computer Software Nanjing University
4、,6,Modularity in Reality,URL pattern matching,Pretty Good Modularity,fits in two boxes,2020/8/14,Institute of Computer Software Nanjing University,7,Modularity in Reality,Logging,Red shows lines of code that handle logging,Not in just one place,Not even in a small number of places,Bad Modularity,Cod
5、e tangling and scattering,2020/8/14,Institute of Computer Software Nanjing University,8,History of Programming Paradigms,In the beginning: Programming in whichever way. Monolithic programs,2020/8/14,Institute of Computer Software Nanjing University,9,History of Programming Paradigms,Structured Progr
6、amming Functional decomposition,Modularity,2020/8/14,Institute of Computer Software Nanjing University,10,History of Programming Paradigms,Object-Oriented Programming Encapsulation this.x =x; this.y=y; TraceSupport.traceExit(“Point.set”); ,A motivating example: Tracing,2020/8/14,Institute of Compute
7、r Software Nanjing University,14,Java API Example,package java.io; public class File implements java.io.Serializable private String path; public boolean exists() SecurityManager security = System.getSecurityManager(); if(security!=null) security.checkRead(path); return exits0(); public boolean canRe
8、ad() SecurityManager security = System.getSecurityManager(); if(security!=null) security.checkRead(path); return canRead0(); ,Same code repeated 16 times in java.io.File,2020/8/14,Institute of Computer Software Nanjing University,15,Crossing cutting concerns,2020/8/14,Institute of Computer Software
9、Nanjing University,16,What is a concern?,A particular goal, concept, or area of interest (requirement) A software system contains: Business (application) logic concerns System-level concerns,2020/8/14,Institute of Computer Software Nanjing University,17,Crosscutting Concerns,Crosscutting is how to c
10、haracterize a concern than spans multiple units of OO modularity Crosscutting concerns resist modularization using normal OO construct,2020/8/14,Institute of Computer Software Nanjing University,18,Separation of Concerns (SoC),Object-Oriented Programming separates and encapsulates some concerns Othe
11、rs end up tangled and scattered Basic problem N dimensions of concerns 1 dimension of implementation structure Tyranny decomposition,2020/8/14,Institute of Computer Software Nanjing University,19,Approaches to SoC,Composition Filters Multi-dimensional Separation of Concerns Adaptive Programming Aspe
12、ct-Oriented Programming Was developed at Xerox PARC (施乐公司 帕洛阿尔托研究中心) (Related) Meta-Object Protocol (MOP) Reflective programming, meta-object protocol,2020/8/14,Institute of Computer Software Nanjing University,20,摘要,Background and Motivation AOP AspectJ Summary,2020/8/14,Institute of Computer Softw
13、are Nanjing University,21,The AOP Idea,Many cross-cuts arent random! They serve specific purposes They have well-defined structure Solets capture the cross-cutting structure in a modular way to better support for “Separation of Concerns”,2020/8/14,Institute of Computer Software Nanjing University,22
14、,Two central problems AOP tries to solve,Code tangling One module, many concerns,Code scattering One concern, many modules,Example: logging,2020/8/14,Institute of Computer Software Nanjing University,23,Two central problems AOP tries to solve,2020/8/14,Institute of Computer Software Nanjing Universi
15、ty,24,AOP approach to SoC,2020/8/14,Institute of Computer Software Nanjing University,25,Prism Analogy,Crosscutting concerns,Implement each concern separately,Weave concerns together,2020/8/14,Institute of Computer Software Nanjing University,26,Basic Mechanisms of AOP,Aspect,Pointcut,Advice,Weaving
16、,2020/8/14,Institute of Computer Software Nanjing University,27,Summary so far,AOP is a software development technique that complements and extends OOP Provides new and powerful ways to modularize “crosscutting concerns” Crosscutting concerns: Behavior that cuts across class boundaries AspectJ is th
17、e leading implementation of AOP that extends Javas OOP model,2020/8/14,Institute of Computer Software Nanjing University,28,摘要,Background and Motivation AOP AspectJ Summary,2020/8/14,Institute of Computer Software Nanjing University,29,What is AspectJ?,A simple and practical aspect-oriented extensio
18、n to Java A general purpose AO language Based on over ten years of research at Xerox PARC Launched in 1998 Transferred to E in 2002 /aspectj/ Latest version: AspectJ 1.6.2,2020/8/14,Institute of Computer Software Nanjing University,30,Design assumptions,Real Community
19、Users Writing aspects Reading aspects Idioms How effective for concerns Modular, reusable and easy to develop and maintain Java compatibility Upward compatibility Platform compatibility Tool compatibility Programmer Compatibility,2020/8/14,Institute of Computer Software Nanjing University,31,AspectJ
20、 Compilation Process,weaving,Application System,ajc: javac extension,2020/8/14,Institute of Computer Software Nanjing University,32,Dynamic VS Static crosscutting,Dynamic crosscutting define additional behavior to run at certain well-defined points in the execution of the program Static crosscutting
21、 modify the static structure of a program (e.g., adding new methods, implementing new interfaces, modifying the class hierarchy),2020/8/14,Institute of Computer Software Nanjing University,33,Concepts in AspectJ,Join Points 连接点 Pointcut 切入点 Advice 通知 Aspect 方面 Introduce 引入,2020/8/14,Institute of Com
22、puter Software Nanjing University,34,High level View of AspectJ,Java Program,AspectJ,Advice,pointcut,advice body,join point,2020/8/14,Institute of Computer Software Nanjing University,35,Join Points Model,Join point is a well-defined point in a programs execution Method call:,Public void move(int dx
23、, int dy) setX(_x+dx); setY(_y+dy); ,Method call join point,2020/8/14,Institute of Computer Software Nanjing University,36,More Join Points,public void setX(int x) _x = x; ,Method execution join point,Field set join point,2020/8/14,Institute of Computer Software Nanjing University,37,All Join Points
24、,method ,2020/8/14,Institute of Computer Software Nanjing University,39,Named Pointcuts,Can be a Named set of join points Capture all the executions of the or method,pointcut move(): execution (void Point.setX(int) | execution (void Point.setY(int);,Name and parameters,Executions of methods with the
25、 specified sig.,or,2020/8/14,Institute of Computer Software Nanjing University,40,More on Pointcuts,Basic pointcuts and pointcuts composition Pointcuts can be composed as boolean expressions with “ after() returning: move() /code here runs after each move ,Example:,2020/8/14,Institute of Computer So
26、ftware Nanjing University,45,Aspects,Mix everything weve seen up to now and put it one or more modular units called Aspects. Looks a lot like a class! Can contain pointcuts, advice declarations, methods, variables .,2020/8/14,Institute of Computer Software Nanjing University,46,How it works,Short an
27、swer: bytecode modification,2020/8/14,Institute of Computer Software Nanjing University,47,A first example,2020/8/14,Institute of Computer Software Nanjing University,48,What it does,Sample Code,2020/8/14,Institute of Computer Software Nanjing University,49,An example from Xeroxs AspectJ Tutorial,So
28、urce ,Sample Code,2020/8/14,Institute of Computer Software Nanjing University,50,AspectJs Introductions,An introduction is an aspect member that allows to Add methods to an existing class Add field to an existing class Extend an existing class with another Implement an interface in an existing class
29、 Convert checked exceptions into unchecked exceptions,2020/8/14,Institute of Computer Software Nanjing University,51,Introduction examples,public int foo.bar(int x); private int foo.counter; declare parents: mammal extends animal; declare parents: MyThread implements MyThreadInterface;,2020/8/14,Ins
30、titute of Computer Software Nanjing University,52,Some Advanced Topics,Aspect Extension (Inheritance) example,2020/8/14,Institute of Computer Software Nanjing University,53,Some Advanced Topics,Aspect Creation (Association) Aspect instance Single (static) vs. Multiple (dynamic) Default: Singleton, c
31、reated when program begins Object (Class) association: perthis, pertarget Controlflow association Percflow, percflowbelow Aspect & Advice Precedence & Interactions,2020/8/14,Institute of Computer Software Nanjing University,54,Performance impact,See “Advice Weaving in AspectJ” “The implementation of
32、 advice weaving introduces very little performance overhead when compared to the same functionality coded by hand.” Does make it easy to create performance destroying code But allows powerful optimizations,2020/8/14,Institute of Computer Software Nanjing University,55,AspectJ Terminology,a join poin
33、t is a well-defined point in the program flow a pointcut is a group of join points advice is code that is executed at a pointcut introduction modifies the members of a class and the relationships between classes a compile time declaration introduces a compile time warning or error upon detection of
34、certain usage patterns an aspect is a module for handling crosscutting concerns Aspects are defined in terms of pointcuts, advice, and introduction Aspects are reusable and inheritable,2020/8/14,Institute of Computer Software Nanjing University,56,Dynamic AOP Systems,Creating aspects at run-time Spe
35、cifying pointcuts at run-time Dynamic code translation (or some special feature of the run-time environment) Enabling/disabling aspects at run-time Pointcuts are dynamic: it can be decided only at run-time whether advices have to be executed or not (based on run-time values, call-stack, etc.),2020/8
36、/14,Institute of Computer Software Nanjing University,57,Other Java AOP sightings,AspectWerkz: load-time/run-time weaving, AOP constructs defined using javadoctags BEA: AOP framework for Weblogic JBoss AOP framework AOP with interceptors Spring framework Limited AOP with proxies J2EE without EJB Asp
37、ectJ2EE JasCo ,2020/8/14,Institute of Computer Software Nanjing University,58,Other Aspect-Oriented Languages,AspectC AspectC+ Aspect.Net Lightweight Python AOP AspectL(Lisp) AspectML AspectPHP,2020/8/14,Institute of Computer Software Nanjing University,59,Middleware & System Level Applications,Security Transaction Persistence Mobility Realtime& Embedded Systems OS ,2020/8/14,Institute of Computer Software Nan
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 事故管理(新)教材
- 八年级英语下册Module4Seeingthetor模块主题写作四课件(新版)外研版
- 传统营销面临的困境
- 常见的营销管理问题
- 2022年度天津市报关员之报关员业务水平考试押题练习试题B卷含答案
- 2023-2024学年级安徽省淮北市西园中学十校联考最后语文试题含解析
- 《西餐厅服务作业设计方案-餐饮服务与管理》
- 2023-2024学年湖南长沙市中学雅培粹校中考试题猜想语文试卷含解析
- 波司登网络营销产品策略总结
- 计算机网络基础试题附有答案
- 建筑密闭空间作业安全措施
- 第7课+全球航路的开辟和欧洲早期殖民扩张【中职专用】《世界历史》(高教版2023·基础模块)
- 湖南省长沙市2022-2023学年八年级下学期语文期中试卷(含答案)
- 2024届河北省衡水市武邑中学中考生物全真模拟试卷含解析
- 全国旅游合同(集合)2024版
- 教师口语智慧树知到期末考试答案2024年
- 慧营销智慧树知到期末考试答案2024年
- 汉字书法课件模板:富_行书65种写法
- SCI、SSCI数据库与论文写作.ppt
- 拔除智齿病历
- 世界风电发展史.ppt
评论
0/150
提交评论