SlideShare una empresa de Scribd logo
1 de 33
AspectJ ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],p.
a simple figure editor p.  operations that move elements Display * 2 Point -x: int -y: int +getX() +getY() +setX(int) +setY(int) Line -p1:Point -p2: Point +getP1() +getP2() +setP1(Point) +setP2(Point) factory methods Figure <<factory>> +makePoint(..) +makeLine(..) FigureElement +setXY(int, int) +draw()
a simple figure editor p.  class  Line implements FigureElement{ private  Point p1, p2; Point getP1() {  return  p1; } Point getP2() {  return  p2; } void  setP1(Point p1) {  this .p1 = p1; } void  setP2(Point p2) {  this .p2 = p2; } void  setXY( int  x,  int  y) {…} } class  Point implements FigureElement { private   int  x = 0, y = 0; int  getX() {  return  x; } int  getY() {  return  y; } void  setX( int  x) {  this .x = x; } void  setY( int  y) {  this .y = y; } void  setXY( int  x,  int  y){…} }
join points p.  a Line a Point returning or throwing dispatch dispatch key points in dynamic call graph returning or throwing returning or throwing imagine  l.setXY(2, 2) a method call a method execution a method execution
join point terminology ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],p.  a Line dispatch method call join points method execution join points
join point terminology: p.  all join points on this slide are within the control flow of this join point imagine  l.setXY(2, 2) a Point a Line a Point
primitive pointcuts ,[object Object],[object Object],[object Object],[object Object],p.  “ a means of identifying join points” matches if the join point is a method call with this signature
pointcut composition p.  whenever a Line receives a    “ void  setP1(Point)” or “ void  setP2(Point)” method call call( void  Line.setP1(Point)) ||  call( void  Line.setP2(Point)); pointcuts compose like predicates, using &&, || and ! or a “void Line.setP2(Point)” call a “void Line.setP1(Point)” call
Pointcuts ,[object Object],[object Object],[object Object],[object Object],[object Object],p.  This pointcut captures all the join points where a  FigureElement moves ,[object Object],[object Object]
named pointcuts ,[object Object],[object Object],p.  pointcut move():  call(void FigureElement.setXY(int,int)) ||  call(void Point.setX(int))  ||  call(void Point.setY(int))  ||  call(void Line.setP1(Point))  ||  call(void Line.setP2(Point )); name parameters more on parameters and how pointcut can expose values at join points in a few slides
Name-based and property-based pointcuts ,[object Object],[object Object],p.  call(void Figure.make*(..)) call(public * Figure.* (..)) cflow(move()) wildcard special primitive pointcut
Example primitive pointcuts ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],p.
Example pointcuts ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],p.
Advice ,[object Object],[object Object],[object Object],[object Object],[object Object],p.  before(): move() {  System.out.println(&quot;about to move&quot;); } after() returning: move() {  System.out.println(&quot;just successfully moved&quot;); }
Exposing context in pointcuts ,[object Object],[object Object],p.  after(FigureElement  fe , int  x , int  y ) returning:  ...SomePointcut... {  System.out.println(fe + &quot; moved to (&quot; + x + &quot;, &quot; + y + &quot;)&quot;);} after(FigureElement fe, int x, int y) returning:  call(void FigureElement.setXY(int, int))  &&  target (fe)  &&  args (x, y) {  System.out.println(fe + &quot; moved to (&quot; + x + &quot;, &quot; + y + &quot;)&quot;);} Advice declares and use parameter list Pointcuts publish values
Exposing context in named pointcuts ,[object Object],[object Object],p.  pointcut setXY(FigureElement fe, int x, int y):  call(void FigureElement.setXY(int, int))  && target(fe)  && args(x, y); after(FigureElement fe, int x, int y) returning:  setXY(fe, x, y) {  System.out.println(fe + &quot; moved to (&quot; + x + &quot;, &quot; + y +  &quot;).&quot;);} pointcut parameter list Pointcuts publish context
explaining parameters… ,[object Object],[object Object],[object Object],[object Object],p.  pointcut  move(Line l):    target(l) && (call( void  Line.setP1(Point)) ||  call( void  Line.setP2(Point))); after (Line line): move(line) {   <line is bound to the line> }
Aspects ,[object Object],[object Object],[object Object],[object Object],p.  aspect Logging {  OutputStream logStream = System.err;  before(): move() {  logStream.println(&quot;about to move&quot;);  } }
Inter-type declarations ,[object Object],p.  aspect PointObserving {  private Vector Point.observers = new Vector();   public static void addObserver(Point p, Screen s) {  p.observers.add(s);  }  public static void removeObserver(Point p, Screen s) {  p.observers.remove(s);  }  pointcut changes(Point p):  target(p) && call(void Point.set*(int));  after(Point p): changes(p) {  Iterator iter = p.observers.iterator();  while ( iter.hasNext() ) {  updateObserver(p, (Screen)iter.next());  }}  static void updateObserver(Point p, Screen s) {  s.display(p);  }}
Examples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],p.
Tracing ,[object Object],[object Object],p.  aspect SimpleTracing {  pointcut tracedCall():  call(void FigureElement.draw(GraphicsContext));  before(): tracedCall() {  System.out.println(&quot;Entering: &quot; +  thisJoinPoint );  } }
Profiling and Logging ,[object Object],[object Object],p.  aspect SetsInRotateCounting {  int rotateCount = 0;  int setCount = 0;  before(): call(void Line.rotate(double)) {  rotateCount++;  }  before(): call(void Point.set*(int))  && cflow(call(void Line.rotate(double))) {  setCount++; } }
Pre- and post- conditions ,[object Object],p.  aspect PointBoundsChecking {  pointcut setX(int x):  (call(void FigureElement.setXY(int, int)) && args(x, *))  || (call(void Point.setX(int)) && args(x));  pointcut setY(int y):  (call(void FigureElement.setXY(int, int)) && args(*, y))  || (call(void Point.setY(int)) && args(y));  before(int x): setX(x) {  if ( x < MIN_X || x > MAX_X )  throw new IllegalArgumentException(&quot;x is out of bounds.&quot;);  }  before(int y): setY(y) {  if ( y < MIN_Y || y > MAX_Y )  throw new IllegalArgumentException(&quot;y is out of   bounds.&quot;);  }}
Contract enforcement ,[object Object],[object Object],p.  aspect RegistrationProtection {  pointcut register():  call(void Registry.register(FigureElement));  pointcut canRegister():  withincode(static * FigureElement.make*(..));  before(): register() && !canRegister() {  throw new IllegalAccessException(&quot;Illegal call &quot; + thisJoinPoint); } }
Contract enforcement ,[object Object],p.  aspect RegistrationProtection {  pointcut register():  call(void Registry.register(FigureElement));  pointcut canRegister():  withincode(static * FigureElement.make*(..));  declare error : register() && !canRegister(): &quot;Illegal call&quot;} }
Change monitoring ,[object Object],[object Object],p.  aspect MoveTracking {  private static boolean dirty = false;  public static boolean testAndClear() {  boolean result = dirty;  dirty = false;  return result;  }  pointcut move():  call(void FigureElement.setXY(int, int)) ||  call(void Line.setP1(Point))  ||  call(void Line.setP2(Point))  ||  call(void Point.setX(int))  ||  call(void Point.setY(int));  after() returning: move() {  dirty = true; } }
Context passing ,[object Object],[object Object],p.  aspect ColorControl {  pointcut CCClientCflow(ColorControllingClient client):  cflow(call(* * (..)) && target(client));  pointcut make(): call(FigureElement Figure.make*(..));  after (ColorControllingClient c) returning  (FigureElement fe):  make() && CCClientCflow(c) {  fe.setColor(c.colorFor(fe)); } }
Providing consistent behavior ,[object Object],[object Object],p.  aspect PublicErrorLogging {  Log log = new Log();  pointcut publicMethodCall():  call(public * com.bigboxco.*.*(..));  after() throwing (Error e): publicMethodCall() {  log.write(e); } } after() throwing (Error e):  publicMethodCall() && !cflow(publicMethodCall()) {  log.write(e); }
wildcarding in pointcuts p.  target(Point) target(graphics.geom.Point) target(graphics.geom.*) any type in graphics.geom target(graphics..*) any type in any sub-package of graphics call( void  Point.setX( int )) call( public  * Point.*(..)) any public method on Point call( public  * *(..)) any public method on any type call( void  Point.getX()) call( void  Point.getY()) call( void  Point.get*()) call( void  get*())  any getter call(Point. new ( int, int )) call( new (..)) any constructor “ *” is wild card “ ..” is multi-part wild card
other primitive pointcuts p.  this(<type name>) within(<type name>) withincode(<method/constructor signature>) any join point at which currently executing object is an instance of type name currently executing code is contained within type name   currently executing code is specified method or constructor get( int  Point.x) set( int  Point.x) field reference or assignment join points
other primitive pointcuts p.  execution(void Point.setX(int)) method/constructor execution join points (actual running method) initialization(Point) object initialization join points staticinitialization(Point) class initialization join points (as the class is loaded) cflow( pointcut designator ) all join points within the dynamic control flow of any join point in  pointcut designator   cflowbelow( pointcut designator ) all join points within the dynamic control flow below any join point in  pointcut designator
Inheritance ,[object Object],[object Object],[object Object],[object Object],p.
Aspect Reuse ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],p.

Más contenido relacionado

La actualidad más candente

C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
Amit Kapoor
 

La actualidad más candente (20)

Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
 
Lecture#8 introduction to array with examples c++
Lecture#8 introduction to array with examples c++Lecture#8 introduction to array with examples c++
Lecture#8 introduction to array with examples c++
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 
C programs
C programsC programs
C programs
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
 
Pointers
PointersPointers
Pointers
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)
 
C++ Pointers
C++ PointersC++ Pointers
C++ Pointers
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
functions
functionsfunctions
functions
 
Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
 

Similar a Introduction to AspectJ

45 aop-programming
45 aop-programming45 aop-programming
45 aop-programming
daotuan85
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 
Boost.Interfaces
Boost.InterfacesBoost.Interfaces
Boost.Interfaces
melpon
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
hassaanciit
 
Function recap
Function recapFunction recap
Function recap
alish sha
 
Function recap
Function recapFunction recap
Function recap
alish sha
 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)
Hattori Sidek
 

Similar a Introduction to AspectJ (20)

Aspect-Oriented Technologies
Aspect-Oriented TechnologiesAspect-Oriented Technologies
Aspect-Oriented Technologies
 
45 aop-programming
45 aop-programming45 aop-programming
45 aop-programming
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Boost.Interfaces
Boost.InterfacesBoost.Interfaces
Boost.Interfaces
 
Pointers [compatibility mode]
Pointers [compatibility mode]Pointers [compatibility mode]
Pointers [compatibility mode]
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
C programming
C programmingC programming
C programming
 
Array Cont
Array ContArray Cont
Array Cont
 
Managing console
Managing consoleManaging console
Managing console
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
C++ L11-Polymorphism
C++ L11-PolymorphismC++ L11-Polymorphism
C++ L11-Polymorphism
 
Function recap
Function recapFunction recap
Function recap
 
Function recap
Function recapFunction recap
Function recap
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
Qprgs
QprgsQprgs
Qprgs
 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)
 

Último

Último (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Introduction to AspectJ

  • 1.
  • 2. a simple figure editor p. operations that move elements Display * 2 Point -x: int -y: int +getX() +getY() +setX(int) +setY(int) Line -p1:Point -p2: Point +getP1() +getP2() +setP1(Point) +setP2(Point) factory methods Figure <<factory>> +makePoint(..) +makeLine(..) FigureElement +setXY(int, int) +draw()
  • 3. a simple figure editor p. class Line implements FigureElement{ private Point p1, p2; Point getP1() { return p1; } Point getP2() { return p2; } void setP1(Point p1) { this .p1 = p1; } void setP2(Point p2) { this .p2 = p2; } void setXY( int x, int y) {…} } class Point implements FigureElement { private int x = 0, y = 0; int getX() { return x; } int getY() { return y; } void setX( int x) { this .x = x; } void setY( int y) { this .y = y; } void setXY( int x, int y){…} }
  • 4. join points p. a Line a Point returning or throwing dispatch dispatch key points in dynamic call graph returning or throwing returning or throwing imagine l.setXY(2, 2) a method call a method execution a method execution
  • 5.
  • 6. join point terminology: p. all join points on this slide are within the control flow of this join point imagine l.setXY(2, 2) a Point a Line a Point
  • 7.
  • 8. pointcut composition p. whenever a Line receives a “ void setP1(Point)” or “ void setP2(Point)” method call call( void Line.setP1(Point)) || call( void Line.setP2(Point)); pointcuts compose like predicates, using &&, || and ! or a “void Line.setP2(Point)” call a “void Line.setP1(Point)” call
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. wildcarding in pointcuts p. target(Point) target(graphics.geom.Point) target(graphics.geom.*) any type in graphics.geom target(graphics..*) any type in any sub-package of graphics call( void Point.setX( int )) call( public * Point.*(..)) any public method on Point call( public * *(..)) any public method on any type call( void Point.getX()) call( void Point.getY()) call( void Point.get*()) call( void get*()) any getter call(Point. new ( int, int )) call( new (..)) any constructor “ *” is wild card “ ..” is multi-part wild card
  • 30. other primitive pointcuts p. this(<type name>) within(<type name>) withincode(<method/constructor signature>) any join point at which currently executing object is an instance of type name currently executing code is contained within type name currently executing code is specified method or constructor get( int Point.x) set( int Point.x) field reference or assignment join points
  • 31. other primitive pointcuts p. execution(void Point.setX(int)) method/constructor execution join points (actual running method) initialization(Point) object initialization join points staticinitialization(Point) class initialization join points (as the class is loaded) cflow( pointcut designator ) all join points within the dynamic control flow of any join point in pointcut designator cflowbelow( pointcut designator ) all join points within the dynamic control flow below any join point in pointcut designator
  • 32.
  • 33.