Docsity

Lecture Slides on Aspect Oriented Programming | CSCI 780, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
1
Aspect-Oriented
Programming
G. Kiczales, J. Lamping,
A. Mendhekar, C. Maeda, C. Lopes,
J. Loingtier, J. Irwin
CSci 780
Advanced Software Engineering
2
Outline
• Motivation
• Basics of AOP
• AspectJ
• Example
• Assessment
• Conclusions
• Discussion
3
Motivation for AOP
• Before AOP, we had:
– Procedural approach
– Object-oriented programming approach
• Problem: There are some
programming problems that fit neither
the procedural approach nor the OOP
approach.
• Solution: Aspect-oriented programming
4
Motivation for AOP
• Image processing
example
– First impleme ntation
was easy to develop
and maintain, but made
poor use of memory
– Optimized ve rsion was
“tangled”
• Cross-cutting concerns
– Tangling
– Scattering
First implementation
Optimized impleme ntation
5
Basics of AOP
• Aspect-oriented programming
modularizes cross-cutting concerns
• Components
– Encapsulated by GP languages
– Functional units
• Aspects
– Not encapsulated by GP languages
– Non-functional units
– Cross-cut
6
Basics of AOP
• Component language
• Component program
• Aspect language
• Aspect program
• Aspect weaver
pf3

Partial preview of the text

Download Lecture Slides on Aspect Oriented Programming | CSCI 780 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

Aspect-Oriented

Programming

G. Kiczales, J. Lamping, A. Mendhekar, C. Maeda, C. Lopes, J. Loingtier, J. Irwin CSci 780 Advanced Software Engineering 2

Outline

  • Motivation
  • Basics of AOP
  • AspectJ
  • Example
  • Assessment
  • Conclusions
  • Discussion 3

Motivation for AOP

  • Before AOP, we had:
    • Procedural approach
    • Object-oriented programming approach
  • Problem: There are some programming problems that fit neither the procedural approach nor the OOP approach.
  • Solution: Aspect-oriented programming 4

Motivation for AOP

  • Image processing example - First implementation was easy to develop and maintain, but made poor use of memory - Optimized version was “tangled”
  • Cross-cutting concerns
    • Tangling
    • Scattering First implementation Optimized implementation 5

Basics of AOP

  • Aspect-oriented programming modularizes cross-cutting concerns
  • Components
    • Encapsulated by GP languages
    • Functional units
  • Aspects
    • Not encapsulated by GP languages
    • Non-functional units
    • Cross-cut 6

Basics of AOP

  • Component language
  • Component program
  • Aspect language
  • Aspect program
  • Aspect weaver

7

Basics of AOP

  • Join point: well-defined point in the execution of a component program
  • Pointcut: collection of join points; a way to pick out join points - Defined in the aspect program
  • Advice: code that executes at each joint point picked out by a pointcut - Defined in the aspect program 8

AspectJ

  • An extension to Java that adds AOP capabilities
  • Developed at Xerox PARC
  • Let’s look at an example… 9 public class TestClass { public void sayHello () { System.out.println ("Hello!"); } public void sayAnyThing (String s) { System.out.println (s); } public static void main (String[] args) { sayHello (); sayAnyThing ("ok."); } } (^10)

Program Output

$ javac TestClass.java $ java TestClass Hello! ok. $ 11 public aspect MyAspect { public pointcut sayMethodCall (): call (public void TestClass.say*() ); public (public void pointcut sayMethodCallArg TestClass.sayAnyThing (String (String)) str): call && args(str); before(): sayMethodCall() { System.out. thisJoinPointStaticPart.println("\n TestClassgetSignature." +().getName() + “ start..." ); } after(): sayMethodCall() { thisJoinPointStaticPart.^ System.out.println("\ngetSignature^ TestClass().." +getName() + “ end..."); } before(String str): sayMethodCallArg(str) { if (str.length() < 3) { System.out. words less than 3 characters");println ("Error: I can't say return; } } } (^12) public class TestClass { public void sayHello () { System.out.println ("Hello!"); } public void sayAnyThing (String s) { System.out.println (s); } public static void main (String[] args) { sayHello (); sayAnyThing ("ok."); } }