• No results found

Ingeniería del So8ware II

N/A
N/A
Protected

Academic year: 2021

Share "Ingeniería del So8ware II"

Copied!
51
0
0

Loading.... (view fulltext now)

Full text

(1)

Seminario.
Programación
Orientada
a
Aspectos


Ingeniería
del
So8ware
II


Pablo
Sánchez
Barreiro


D

PTO

.


DE


M

ATEMÁTICAS

,
E

STADÍSTICA

Y

COMPUTACIÓN


p.sanchez@unican.es

Este
tema
se
publica
bajo
Licencia:


(2)

Table of Contents

1 Introduction: Why we need Aspect-Oriented Programming

2 Aspect-Oriented Programming

3 Current Challenges

4 What AOSD Is Not About

5 AOSD and Related Technologies

6 Conclusions

(3)

Introduction Crosscutting Concerns

Crosscutting Concerns Drawbacks

Happiness

Sadness

Module A Module B Module C Module D Module E

Base Functionality

Fault Tolerance v2.0 Access Control

Encryption

(4)

Introduction Crosscutting Concerns

Case Study: Apache Tomcat

(5)

Introduction Crosscutting Concerns

Case Study: Apache Tomcat

(6)

Introduction Crosscutting Concerns

Case Study: Apache Tomcat

(7)

Introduction Crosscutting Concerns

Motivating example: Access Control

AccessControl class [ ]

+askForCredentials( out username : String, out password : String )

AccessControlView

+getAccess() : Boolean

+getSelectiveAccess( String : String )

AccessControl -name : String -address : String -religion : String -diseases : String [0..*] +getName() : String +getAddress() : String +getReligion() : String +getDiseases() : String [0..*] Student +authenticator «use»

(8)

Introduction Crosscutting Concerns

Motivating example: Access Control

public class Student {

protected String religion;

protected AccessControl authenticator =

new AccessControl();

public String getReligion() {

String result = null;

if (authenticator.getAccess()) { result = this.religion; } // if

return result;

} // getReligion

} // Student

public class Student {

protected String religion;

protected AccessControl authenticator =

new AccessControl();

public String getReligion() {

String result = null;

if (authenticator.getAccess()) { result = this.religion; } // if

return result;

} // getReligion

} // Student

(9)

Introduction Crosscutting Concerns

Motivating example: Access Control

public List<String> getDiseases() { List<String> result = null; if (authenticator.getAccess()) {

result = this.diseases; } // if

return result; } // getDiseases

(10)

Introduction Crosscutting Concerns

Main Shortcoming of Crosscutting Concerns

Happiness

Sadness

Module A Module B Module C Module D Module E Base Functionality

Fault Tolerance v2.0 Access Control

Encryption @#&

(11)

Introduction Conclusions

Conclusions

Scattering

A concern appears spread over several software modules.

Tangling

Several concern appears software modules.

1 Scattering:Decreases encapsulation, (consequently decreases

cohesion),creates redundancies, hinders reutilization of the

crosscutting concern and increase coupling.

2 Tangling:Decreases cohesion, (consequently hampers reutilization),

(12)

Introduction Empirical Evidence

Concern-Oriented Metrics [Sant’Anna et al., 2007]

CDC Concern Diffusion over Classes

CDO Concern Diffusion over Operations

CIC Class-Level Interlacing between Concerns

OOC Operation-Level Overlapping between Concerns

ACC Afferent Coupling between Classes

ECC Efferent Coupling between Classes

(13)

Introduction Empirical Evidence

Concern-Oriented Metrics [Sant’Anna et al., 2007]

AccessControl

class [ ]

+askForCredentials( out username : String, out password : String )

AccessControlView

+getAccess() : Boolean +getSelectiveAccess( String : String )

AccessControl -name : String -address : String -religion : String -diseases : String [0..*] +getName() : String +getAddress() : String +getReligion() : String +getDiseases() : String [0..*] Student +authenticator «use»

CDC CDO CIC OOC

Data Storage (base) 1 4 1 1

AccessControl 3 5 1 1

ACC ECC LCC

Student 0 1 2

AccessControl 1 1 1

(14)

Aspect-Oriented Programming

Table of Contents

1 Introduction: Why we need Aspect-Oriented Programming

2 Aspect-Oriented Programming

3 Current Challenges

4 What AOSD Is Not About

5 AOSD and Related Technologies

6 Conclusions

(15)

Aspect-Oriented Programming Overview

Aspect-Oriented Programming Principle

Module B Module A

(16)

Aspect-Oriented Programming Overview

Aspect-Oriented Programming Principle

Module B Module A Joinpoint Joinpoint Joinpoint Joinpoint

(17)

Aspect-Oriented Programming Overview

Aspect-Oriented Programming Principle

Access Control Module B Module A Fault Tolerance Encryption Aspect Aspect Aspect
(18)

Aspect-Oriented Programming Overview

Aspect-Oriented Programming Principle

Access Control Module B Module A Fault Tolerance Encryption Pointcut Pointcut Pointcut
(19)

Aspect-Oriented Programming Aspect-Oriented Weaving

Weaving Process

Base Model

Aspect-Oriented Weaving Process

A sp e ct W e a v e r Pointcut Model Aspect Model

Woven Base Model

C o m m o n C o m p il e r 100101 101100 010101 Compiled Code

(20)

Aspect-Oriented Programming Aspect-Oriented Weaving

Weaving Process

Concern Identifier Requirements Weaver Concern implementation Aspectual Decomposition Aspectual Recomposition Final System
(21)

Aspect-Oriented Programming Aspect-Oriented Weaving

Kinds of Aspect-Oriented Weaving

Static Weaving Aspects are woven at compile time [Kiczales et al., 2001].

Load-Time Weaving Aspects are woven at class load-time [Laddad, 2001, Chiba, 2000].

Dynamic Weaving Aspects can be woven and even unwoven at runtime [Pinto et al., 2005, Suv´ee et al., 2003]. It is particulary interesting for context-aware

(22)

Aspect-Oriented Programming Example: Access Control as an Aspect

Access Control With AspectJ

public aspect AccessControlAspect {

pointcut guardedMethods():

call(String Student.getReligion()); String around() : guardedMethods() {

AccessControl guard = new AccessControl(); String returnValue = null;

if (guard.getAccess()) { returnValue = proceed(); } // if

return returnValue; } // around guardedMethods

} // AccessControlAspect

public aspect AccessControlAspect { pointcut guardedMethods():

call(String Student.getReligion()); String around() : guardedMethods() {

AccessControl guard = new AccessControl(); String returnValue = null;

if (guard.getAccess()) { returnValue = proceed(); } // if

return returnValue; } // around guardedMethods

} // AccessControlAspect

public aspect AccessControlAspect { pointcut guardedMethods():

call(String Student.getReligion()); String around() : guardedMethods() {

AccessControl guard = new AccessControl(); String returnValue = null;

if (guard.getAccess()) { returnValue = proceed(); } // if

return returnValue; } // around guardedMethods

} // AccessControlAspect

public aspect AccessControlAspect { pointcut guardedMethods():

call(String Student.getReligion()); String around() : guardedMethods() {

AccessControl guard = new AccessControl(); String returnValue = null;

if (guard.getAccess()) { returnValue = proceed(); } // if

return returnValue; } // around guardedMethods

(23)

Aspect-Oriented Programming Example: Access Control as an Aspect

A Clean Student Class

public class Student {

protected String religion; public String getReligion() {

return this.religion; } // getReligion

(24)

Aspect-Oriented Programming Quantification

Wildcard-based Quantified Pointcuts

public aspect QuantifiedAccessControlAspect {

pointcut guardedMethods(): call(* Student.get*(..)); Object around() : guardedMethods() {

AccessControl guard = new AccessControl(); Object returnValue = null;

if (guard.getAccess()) { returnValue = proceed(); } // if return returnValue; } // around guardedMethods } // QuantifiedAccessControlAspect

public aspect QuantifiedAccessControlAspect {

pointcut guardedMethods(): call(* Student.get*(..)); Object around() : guardedMethods() {

AccessControl guard = new AccessControl(); Object returnValue = null;

if (guard.getAccess()) { returnValue = proceed(); } // if return returnValue; } // around guardedMethods } // QuantifiedAccessControlAspect

(25)

Aspect-Oriented Programming Annotation-based Quantification

Annotation-based Quantified Pointcuts

public class Student {

protected String religion;

@AccessControlRequired

public String getReligion() { return this.religion; } // getReligion

(26)

Aspect-Oriented Programming Annotation-based Quantification

Annotation-based Quantified Pointcuts

public aspect AnnotationBasedAspect {

pointcut guardedMethods():

call(@AccessControlRequired * *.*(..));

Object around() : guardedMethods() {

AccessControl guard = new AccessControl(); Object returnValue = null;

if (guard.getAccess()) { returnValue = proceed(); } // if return returnValue; } // around guardedMethods } // AnnotationBasedAspect

public aspect AnnotationBasedAspect { pointcut guardedMethods():

call(@AccessControlRequired * *.*(..));

Object around() : guardedMethods() {

AccessControl guard = new AccessControl(); Object returnValue = null;

if (guard.getAccess()) { returnValue = proceed(); } // if return returnValue; } // around guardedMethods } // AnnotationBasedAspect

(27)

Aspect-Oriented Programming Reflection

Some Basic & Free Reflection

A c c e s s C o n t r o l c l a s s [ ] + a s k F o r C r e d e n t i a l s ( o u t u s e r n a m e : S t r i n g , o u t p a s s w o r d : S t r i n g ) A c c e s s C o n t r o l V i e w + g e t A c c e s s ( ) : B o o l e a n + g e t S e l e c t i v e A c c e s s ( S t r i n g : S t r i n g ) A c c e s s C o n t r o l - n a m e : S t r i n g - a d d r e s s : S t r i n g - r e l i g i o n : S t r i n g - d i s e a s e s : S t r i n g [ 0 . . * ] + g e t N a m e ( ) : S t r i n g + g e t A d d r e s s ( ) : S t r i n g + g e t R e l i g i o n ( ) : S t r i n g + g e t D i s e a s e s ( ) : S t r i n g [ 0 . . * ] S t u d e n t + a u t h e n t i c a t o r « u s e »

(28)

Aspect-Oriented Programming Reflection

Some Basic & Free Reflection

public aspect ReflectionAccessControlAspect {

pointcut guardedMethods():

call(String Student.getReligion()); String around() : guardedMethods() {

AccessControl guard =new AccessControl(); String returnValue = null;

if (guard.getSelectiveAccess( thisJoinPoint.getSignature(). getName())) { returnValue = proceed(); } // if returnreturnValue; } // around guardedMethods } // ReflectionAccessControlAspect

public aspect ReflectionAccessControlAspect { pointcutguardedMethods():

call(String Student.getReligion()); Stringaround() : guardedMethods() {

AccessControl guard = new AccessControl(); String returnValue = null;

if(guard.getSelectiveAccess( thisJoinPoint.getSignature(). getName())) { returnValue = proceed(); } // if return returnValue; } // around guardedMethods } // ReflectionAccessControlAspect

(29)

Aspect-Oriented Programming Reflection

Concern-Oriented Metrics Revisited

AccessControlAspect

class [ ]

+askForCredentials( out username : String, out password : String ) AccessControlView -name : String -address : String -religion : String -diseases : String [0..*] +getReligion() : String +getName() : String +getAddress() : String

+getDiseases( diseases : String [0..*] ) Student

+getAccess() : Boolean +getSelectiveAccess( String : String )

AccessControl

«crosscut»

CDC CDO CIC OOC

Data Storage (base) 1 (1) 4 (4) 0 (1) 0 (1)

AccessControl 2 (2) 3 (5) 0 (1) 0 (1)

ACC ECC LCC

Student 1 (0) 0 (1) 1 (2)

AccessControl 0 (1) 2 (1) 1 (1)

(30)

Current Challenges

Table of Contents

1 Introduction: Why we need Aspect-Oriented Programming

2 Aspect-Oriented Programming

3 Current Challenges

4 What AOSD Is Not About

5 AOSD and Related Technologies

6 Conclusions

(31)

Current Challenges

Current Hot Research Topics on AOSD

1 Semantic pointcuts [Ostermann et al., 2005].

2 Reusable aspects (e.g Complex Transaction

Management) [Kienzle and G´elineau, 2006].

3 Aspect interference/conflicts [Douence et al., 2002,

Douence et al., 2004, Altahat et al., 2008].

4 Complex pointcuts [Allan et al., 2005].

(32)

Current Challenges

Current Hot Research Topics on AOSD

<<CallBehavior>> calculateDiscount <<CallBehavior>> minus first proceed <<proceed>> price price : Real checkOut(..) (.*):(.*) <?cart>(.*) : ShoppingCart (.*):(.*) newCreditCard(..) <?ws>(.*): WebServiceBank termsAndConditionsOfSeasonalRebate [*] <?jp>: approveCredit(<?cc>(.*):PaymentMethod, <?price>(.*):Real)) <?cc>(.*):CreditCard ?jp ?price

(33)

What AOSD is not about

Table of Contents

1 Introduction: Why we need Aspect-Oriented Programming

2 Aspect-Oriented Programming

3 Current Challenges

4 What AOSD Is Not about

5 AOSD and Related Technologies

6 Conclusions

(34)

What AOSD is not about AOSD is not View-Based Software Development

AOSD is not View-Based Software Development

class addItem

UserGUI IShop ShoppingCart

+ books 0 ..*

+ addItem (book :Book , amount :int ) << theme >>

AddItem

<< theme >>

CheckOut

class checkOut

UserGUI IShop ShoppingCart

Delivery + checkOut () IDelivery Bank IBank sdcheckOut

UserGUI ShoppingCart Delivery Bank checkDelivery (address = -,weight = -,size = -)

approveCredit (ccNumber = -,amount = -)

merge Books

sdaddItem

(35)

What AOSD is not about AOSD is not Feature-Oriented Software Development

AOSD is not Feature-Oriented Software Development

Architecture

class [ ]

SmartEnergyMng

+openWindow( id : Integer ) +closeWindow( id : Integer ) +adjustTemperature( id : Integer, temp : float )

Gateway

+operationMode : TempUnits

ThermometerCtrl Sensor InitialModel

+changeValue( id : Integer, value : float ) +emergence( a : Sensor, value : float )

Gateway

+id : Integer

+setValue( value : float )

Actuator

+id : Integer

+getValue() : float

Sensor

HeaterMng

+adjustTemperature( id : Integer, temp : float )

Gateway +units : TempUnits +set( t : float ) HeaterCtrl FAHRENHEIT CELSIUS «enumeration» TempUnits Actuator WindowMng +openWindow( id : Integer ) +closeWindow( id : Integer ) Gateway +open() +close() WindowCtrl Actuator LightMng +switchLight( id : Integer ) Gateway +switch() LightCtrl Actuator +indoorTherm 1 +outdoorTherm 1 +sensors 0..* +actuators 0..* +gtw 0..1 +heaters 1..* +windows 1..* +lights 1..* «merge» «merge» «merge» «merge» «merge»

(36)

AOSD and Related Technology

Table of Contents

1 Introduction: Why we need Aspect-Oriented Programming

2 Aspect-Oriented Programming

3 Current Challenges

4 What AOSD Is Not About

5 AOSD and Related Technologies

6 Conclusions

(37)

AOSD and Related Technology

AOSD and Related Technology

1 Component platforms/Application Servers/Container

Technology

◮ Component platforms offer a set of fixed services. ◮ Configuration of each service is often different. ◮ Component platforms are often heavier.

2 Reflection:AOP is reflection for human beings.

3 Design Patterns, Dynamic Proxies: The aspect-oriented weaver

(38)

AOSD and Related Technology

AOSD in Industry

1 Spring framework for Enterprise Java.

2 SpringSource dm Server, SpringSource tc Server, Spring Roo y

Magma.

3 GlassBox, Perf4J, Contract4J, JXInsight, MaintainJ.

4 Websphere, MySQL, JBoss, Oracle Toplink,

J2ME [Rashid et al., 2010].

5 Siemens Healthcare [Rashid et al., 2010].

6 Motorola Weavr [Cottenier et al., 2007].

7 Oficina Virtual Fundaci´on Retevisi´on [Pinto et al., 2005]

8 Digital Publishing [de Beeck et al., 2009].

(39)

Conclusions

Table of Contents

1 Introduction: Why we need Aspect-Oriented Programming

2 Aspect-Oriented Programming

3 Current Challenges

4 What AOSD Is Not About

5 AOSD and Related Technologies

6 Conclusions

(40)

Conclusions

Conclusions

Aspect-Oriented Software Development

Aspect-Oriented Software Development can help to improve

modularization of crosscutting concerns, easing maintenance and evolution.

Access Control Code:

http://personales.unican.es/sanchezbp/teaching/ao/accesscontrol.zip

More Information:

(41)

References

Table of Contents

1 Introduction: Why we need Aspect-Oriented Programming

2 Aspect-Oriented Programming

3 Current Challenges

4 What AOSD Is Not About

5 AOSD and Related Technologies

6 Conclusions

(42)

References

Referencias I

Allan, C., Avgustinov, P., Christensen, A. S., Hendren, L. J., Kuzins, S., Lhot´ak, O., de Moor, O., Sereni, D., Sittampalam, G., and Tibble, J. (2005).

Adding trace matching with free variables to AspectJ.

In Johnson, R. E. and Gabriel, R. P., editors,Proc. of the 20th Annual Conference on Object-Oriented Programming, Systems, Languages, and Applications, (OOPSLA), pages 345–364.

Altahat, Z., Elrad, T., and Tahat, L. (2008).

Applying Critical Pair Analysis in Graph Transformation Systems to Detect Syntactic Aspect Interaction in UML State Diagrams. InProc. of the 20th Int. Conference on Software Engineering & Knowledge Engineering (SEKE), pages 905–911, San Francisco (California, USA).

(43)

References

Referencias II

Brichau, J. and D‘Hondt, T. (2005).

Introduction to Aspect-Oriented Software Development.

Deliverable D17 AOSD-Europe-VUB-02, AOSD-Europe Network of Excellence, Brussels.

Chiba, S. (2000).

Load-Time Structural Reflection in Java.

In Bertino, E., editor,Proc. of the 14th European Conference on Object-Oriented Programming (ECOOP), pages 313–336, Sophia Antipolis and Cannes (France).

Colyer, A., Clement, A., Harley, G., and Webster, M. (2004).

Eclipse AspectJ: Aspect-Oriented Programming with AspectJ and the Eclipse AspectJ Development Tools.

(44)

References

Referencias III

Cottenier, T., van den Berg, A., and Elrad, T. (2007).

Motorola WEAVR: Aspect and model-Driven Engineering.

Journal of Object Technology (JOT), 6(7):51–88.

de Beeck, S. O., Landuyt, D. V., Truyen, E., and Joosen, W. (2009).

Building a Next-Generation Digital News Publishing Platform with AOSD.

InProc. of the 8th Int. Conference on Aspect-Oriented Software Development (AOSD), Charlottesvile (Virginia, USA).

(45)

References

Referencias IV

Douence, R., Fradet, P., and S¨udholt, M. (2002).

A Framework for the Detection and Resolution of Aspect Interactions. In Batory, D. S., Consel, C., and Taha, W., editors,Proc. of the Int. Conference on Generative Programming and Component Engineering (GPCE), volume 2487 ofLNCS, pages 173–188, Pittsburgh,

(Pennsylvania, USA).

Douence, R., Fradet, P., and S¨udholt, M. (2004).

Composition, Reuse and Interaction Analysis of Stateful Aspects. InProc. of the 3rd Int. Conference on Aspect-Oriented Software Development (AOSD), pages 141–150, Lancaster (UK).

Elrad, T., Ak¸sit, M., Kiczales, G., Lieberherr, K., and Ossher, H. (2001).

Discussing Aspects of AOP.

(46)

References

Referencias V

Filman, R. E., Elrad, T., Clarke, S., and Ak¸sit, M., editors (2004).

Aspect-Oriented Software Development. Addison-Wesley, Boston.

Fuentes, L., G´amez, N., and S´anchez, P. (2009).

Aspect-Oriented Design and Implementation of Context-Aware Pervasive Applications.

Innovations in Systems and Software Engineering, 5(1):79–93.

Hannemann, J. and Kiczales, G. (2002).

Design Pattern Implementation in Java and AspectJ. InProc. of the 17th Int. Conference on Object-Oriented

Programming, Systems, Languages, and Applications (OOPSLA), pages 161–173, Seattle (Washington, USA).

(47)

References

Referencias VI

Kiczales, G., Hilsdale, E., Hugunin, J., Kersten, M., Palm, J., and Griswold, W. G. (2001).

An Overview of AspectJ.

In Knudsen, J. L., editor, Proc. of the 15th European Conference on Object-Oriented Programming (ECOOP), volume 2072 of Lecture Notes in Computer Science, pages 327–353, Budapest (Hungary).

Kiczales, G., Lamping, J., Mendhekar, A., Maeda, C., Lopes, C. V., Loingtier, J.-M., and Irwin, J. (1997).

Aspect-Oriented Programming.

In Ak¸sit, M. and Matsuoka, S., editors,Proc. of the 11th European Conference on Object-Oriented Programming (ECOOP), volume 1241 ofLecture Notes in Computer Science, pages 220–242,

(48)

References

Referencias VII

Kienzle, J. and G´elineau, S. (2006).

AO challenge - Implementing the ACID properties for Transactional Objects.

In Filman, R. E., editor,Proc. of the 5th Int. Conference on Aspect-Oriented Software Development (AOSD), pages 202–213.

Laddad, R. (2001).

I want my AOP! Java World,

http://www.javaworld.com/javaworld/jw-01-2002/jw-0118-aspe

Ostermann, K. (2008).

Reasoning about Aspects with Common Sense.

(49)

References

Referencias VIII

Ostermann, K., Mezini, M., and Bockisch, C. (2005).

Expressive Pointcuts for Increased Modularity.

In Black, A. P., editor,Proc. of the 19th European Conference on Object-Oriented Programming (ECOOP), volume 3586 of LNCS, pages 214–240, Glasgow (UK).

Pinto, M., Fuentes, L., and Troya, J. M. (2005).

A Dynamic Component and Aspect-Oriented Platform.

Computer Journal, 48(4):401–420.

Rashid, A., Cottenier, T., Greenwood, P., Chitchyan, R., Meunier, R., Coelho, R., S¨udholt, M., and Joosen, W. (2010).

Aspect-Oriented Software Development in Practice: Tales from AOSD-Europe.

(50)

References

Referencias IX

Sant’Anna, C., Figueiredo, E., Garcia, A. F., and de Lucena, C. J. P. (2007).

On the Modularity of Software Architectures: A Concern-Driven Measurement Framework.

In Oquendo, F., editor,Proc. of the 1st European Conference on Software Architecture (ECSA), pages 207–224, Aranjuez (Spain).

Suv´ee, D., Vanderperren, W., and Jonckers, V. (2003).

JAsCo: an Aspect-Oriented Approach Tailored for Component-Based Software Development.

InProc. of the 2nd Int. Conference on Aspect-Oriented Software Development (AOSD), pages 21–29, Boston (Massachusetts, USA).

(51)

Questions

http://personales.unican.es/sanchezbp/teaching/ao/accesscontrol.zip http://www.aosd-europe.net http://www.javaworld.com/javaworld/jw-01-2002/jw-0118-aspe

References

Related documents

for my study and provided a thorough discussion of how court cases, especially those in the Richmond Mayor’s court, offered insights into the lives and social conditions of

SIZE (return array size and type information, it can be seen from the Variable Watch Window).. TOTAL (sum

This provider of education and information to successful business owners is the creator of The Seven Step Exit Planning Process™ (See Your Action Checklist for Leaving Your

A 3 Meridian Technologies www.meridiantechnologies.net Management Trainee/IT recruiter (Charlotte, NC), Experienced IT Recruiters, Entry Level Staff Consultants B 61

the system have included the replacement of traditional early-maturing beef-breed sires with late-maturing “continental”- breed sires, the replacement of early- maturing

As an ironworks has many hot products and facilities such as blast furnace, mixing furnace, converters, continuous steel casting and hot strip mills, asbestos as

The term ‘TSE infectious healthcare waste’ applies to high and low infectivity tissues from persons with confirmed or suspected TSEs, or high infectivity tissue from persons with

Major concentration of the paper has been on capturing the live traffic using the network protocol analyzer Wireshark and on the basis of analysis scripts using