复旦大学:《面向对象分析和设计》课程资料_UML和模式_AOP Aspect Oriented Programming

AOP Aspect Oriented Programming
AOP Aspect Oriented Programming

考虑一个PoS机的销售处理模块 > > Processsalehandler ProcessReturnHandler +start sale O +startReturn( +enterItem () +finishReturn() +finishSale +modifysale(
问题 • 考虑一个POS机的销售处理模块

如何处理权限问题 在处理一个销售的过程中,收银员可以执行启 动销售等操作( startsale),如果需要修改销售的 内容( change Sale)则需要由管理员执行 如何处理权限问题? 在每段方法的开头加上权限处理的代码? 或者应该将 Process Salehandler分解为两个类?
如何处理权限问题 – 在处理一个销售的过程中,收银员可以执行启 动销售等操作(startSale),如果需要修改销售的 内容(changeSale)则需要由管理员执行。 – 如何处理权限问题? • 在每段方法的开头加上权限处理的代码? • 或者应该将ProcessSaleHandler分解为两个类?

第一种方法 public iSale startSaleo t if (securityManager.isFunction Valid4 CurrentUser/"startSale") return new SaleMemImplO else throw new SecurityViolated Exception( startSale"; 问题 在所有的业务代码中都混杂了权限相关代码 (Code tangling 与权限相关的代码分散在各处( Code scattering)
第一种方法 • 问题: – 在所有的业务代码中都混杂了权限相关代码 (Code tangling) – 与权限相关的代码分散在各处(Code scattering ) public ISale startSale() { if (securityManager.isFunctionValid4CurrentUser("startSale")) return new SaleMemImpl(); else throw new SecurityViolatedException("startSale"); }

第二种方法 > > CasherHandler Adminhandler + startSale O +modifySale O +enterItem o +finishSale o +startReturn o +finishReturn o 类提供了一种层次化的分类方法,但问题 是,他只能提供一个维度的分类方法
第二种方法 • 类提供了一种层次化的分类方法,但问题 是,他只能提供一个维度的分类方法

Security aspect的实现( Spring) public class Security CheckAspect implements MethodInterceptor( SEcurity Manager security Manager public void setSecurity Manager Security Manager security Manager)i this securityManager= security Manager; @Override public object invoke MethodInvocation invocation throws Throwable f String funcName invocation getMethod ( getName() if (security Manager is Function Valid CurrentUser(invocation. getMethod(getName) return invocation. proceed throw new Security Violated Exception(funcName);
public class SecurityCheckAspect implements MethodInterceptor{ ISecurityManagersecurityManager; public void setSecurityManager(ISecurityManagersecurityManager) { this.securityManager = securityManager; } @Override public Object invoke(MethodInvocation invocation) throws Throwable { String funcName = invocation.getMethod().getName(); if (securityManager.isFunctionValid4CurrentUser(invocation.getMethod().getName())) return invocation.proceed(); else throw new SecurityViolatedException(funcName); } } Security Aspect的实现(Spring)

Code tangling Business log Transaction Security management Implementation modules
Code tangling

Code scattering API invocations Accounting module Secur module ATM module Database module
Code scattering

N-dimensional concern Security Transaction management Security Implementation mapping Business logic Business logic once space Implementation space
N-dimensional concern

Security Aspect的实现( Aspect public aspect SecurityAspect i private SEcurity Manager security Manager= Security Manager. getInstanceo pointcut securedAccess() execution(* IUsecaseHandler+. ())B //Advice before ( securedAccess(t String function Name= thisJoin Point getsignature().getName 0 if(Security Manager. isFunction Valid4CurrentUser(function Name )) throw new Security Violated Exception(function Name);
Security Aspect的实现(AspectJ) public aspect SecurityAspect { private ISecurityManagersecurityManager = SecurityManager.getInstance(); pointcut securedAccess(): execution ( * IUsecaseHandler+.*(..) ); //Advice before(): securedAccess(){ String functionName = thisJoinPoint.getSignature().getName(); if(!securityManager.isFunctionValid4CurrentUser(functionName)) throw new SecurityViolatedException(functionName); } }
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_复习:OOAD部分.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 21 测试驱动的开发与重构.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 19 Chapter 20 Chapter 22.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 18 - 使用GRASP的对象设计示例.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 17 - GRASP基于职责设计对象.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 16 - UML类图.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 15 - UML交互图.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 14 - 迈向对象设计.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 13 - 逻辑架构和UML包图.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 11 - 操作契约.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 10 - 系统顺序图.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 9 - 领域模型.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 8 - 细化阶段的迭代——基础.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 7 - 其他需求.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 6 - 用例.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 4 Chapter 5 - 初始阶段的需求.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 3 - 案例分析 THE NEXTGEN POS SYSTEM.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_OOP:Object-Oriented Programming.pptx
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 2 - 迭代、进化和敏捷.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Chapter 1 - 面向对象分析和设计.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Hibernate Persistence.ppt
- 复旦大学:《面向对象分析和设计》课程资料_UML和模式_Hibernate 演示场景.pptx
- 复旦大学:《电子商务》课程资源_教学大纲.pdf
- 复旦大学:《电子商务》课程资源_教学案例:The Business Model-Recent Developments and Future Research-JOM2011.pdf
- 复旦大学:《电子商务》课程资源_教学研究:Online Game Addiction among Adolescents_Motivation and Prevention Factors.pdf
- 复旦大学:《电子商务》课程资源_教学研究:Research On The Utility Of An Advanced ACA In Context-Aware Tour Planning System.pdf
- 复旦大学:《电子商务》课程PPT课件_第二次课 电子商务的商业模式与分类.ppt
- 复旦大学:《电子商务》课程PPT课件_第一次课 引言(胥正川).ppt
- 复旦大学:《电子商务》课程PPT课件_第三次课 电子商务过程及相关因素(电子商务创业).ppt
- 复旦大学:《电子商务》课程PPT课件_第四次课 电子商务商业计划书写作 Creating a Winning E-Business Second Edition.ppt
- 复旦大学:《电子商务》课程PPT课件_第七次课 B2C电子商务——网上零售.pptx
- 复旦大学:《电子商务》课程PPT课件_第九次课 B2B电子商务(B2B行业平台).ppt
- 复旦大学:《电子商务》课程PPT课件_第五次课 商业模式的概念与内涵(发现商业模式).ppt
- 复旦大学:《电子商务》课程PPT课件_第八次课 电子商务模式与应用课程主题案例分析与展示——电子商务团购.ppt
- 复旦大学:《电子商务》课程PPT课件_第六次课 电子商务运营与管理 Getting Your E-Business Off The Ground.ppt
- 复旦大学:《电子商务》课程PPT课件_第六次课 电子商务运营与管理 Operating Your E-Business.ppt
- 复旦大学:《电子商务》课程PPT课件_第十次课 社会化电子商务——Hold住社会化媒体营销.ppt
- 复旦大学:《计算机图形学》课后习题答案_1.docx
- 复旦大学:《计算机图形学》课后习题答案_2.docx
- 复旦大学:《计算机图形学》课后习题答案_3.docx