• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
AOP crashcourse 2007
 

AOP crashcourse 2007

on

  • 301 views

Short introduction to aspect-oriented programming.

Short introduction to aspect-oriented programming.

Statistics

Views

Total Views
301
Views on SlideShare
296
Embed Views
5

Actions

Likes
1
Downloads
3
Comments
0

1 Embed 5

http://www.linkedin.com 5

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    AOP crashcourse 2007 AOP crashcourse 2007 Presentation Transcript

    • Aspect-OrientedProgrammingBjörn GranvikAOPIn 10 minutes
    • AspectJ is:An AOP extension to JavaJava platform compatibleOpen Source (Mozilla style)C -> C++ Java -> AspectJA general AO langauge
    • AOP: Crosscut”Crosscutting concerns” System wide areas of interestFor instance: Security Transactions Caching …
    • Tomcat: XML parsingGood modularity
    • Tomcat: URL Pattern matchingStill nice fit using inheritence
    • Tomcat: LoggingLogging all over the code!aspect• Lets make it into a module– an aspect of logging
    • Language elementsjoin point”kodpunkt” The possible ”wheres”. Well defined points in the execution of a program.pointcut”punktsnitt” A filter picking out interesting join points.advice”direktiv” Code to be run at join points.= aspect
    • Join PointWell defined point during execution A call to a method Method invocation Class initialization Object instantiationUsed as ”hooks” foraspectsNameBean bean = new NameBean();bean.foo();InvocationCallObject instantiationClass initialization
    • PointcutCollection of joinpoints that defines where theadvice should be appliedexecution(* foo(..)) or execution(* bar(int))
    • AdviceAdditional code executed at a specific joinpointVarious types that defines when the adviceshould be executed Before After Around Throws ...Example Log a method call
    • Simple Example: UML
    • Simple Examplepointcut moves():calls(void Line.setP1(Point)) ||calls(void Line.setP2(Point)) ||calls(void Point.setX(int)) ||calls(void Point.setY(int)) ||calls(void FigureElement.incrXY());
    • Simple Examplepointcut moves():calls(void Line.setP1(Point)) ||calls(void Line.setP2(Point)) ||calls(void Point.setX(int)) ||calls(void Point.setY(int)) ||calls(void FigureElement.incrXY());after(): moves() {System.println.out(”Moved!”);}
    • Simple Exampleaspect MoveTracking {pointcut moves():calls(void Line.setP1(Point)) ||calls(void Line.setP2(Point)) ||calls(void Point.setX(int)) ||calls(void Point.setY(int)) ||calls(void FigureElement.incrXY());after(): moves() {System.println.out(”Moved!”);}}
    • Simple Example: thisJoinPointaspect MoveTracking {pointcut moves():calls(void Line.setP1(Point)) ||calls(void Line.setP2(Point)) ||calls(void Point.setX(int)) ||calls(void Point.setY(int)) ||calls(void FigureElement.incrXY());after(): moves() {System.println.out(”Moved from:”+ thisJoinPoint );}}
    • Simple Example: wildcardaspect MoveTracking {pointcut moves():calls(void Line.set*(Point)) ||calls(void Point.set*(int)) ||calls(void FigureElement.incrXY());after(): moves() {System.println.out(”Moved from:”+ thisJoinPoint );}}
    • Hello
    • WorldAspect
    • HelloWorld!
    • ProsPowerful new paradigm improving modularityEasier system evolutionLate binding in design decisionsMore code reuseExtension of Java, therefore it runs on existing systems andtoolsIt integrates well with different toolsUsed in good frameworks such as Spring
    • ConsMore to learn?Yes. Use small doses, get experience.Requires new design strategies?Yes.Extension to Java?!Use AspectWerkzBreaks encapsulation?Yes, but OOP breaks the technical concerns instead.Start with small and focused aspects.Use available tools.