80 likes | 193 Views
This survey examines Aspect-Oriented Programming (AOP), highlighting its potential to tackle the growing complexity in software development. AOP facilitates the separation of concerns, thereby improving code cleanliness and modularity. The traditional approach to logging is contrasted with AOP techniques, demonstrating how logging functionality can be isolated from core application logic. The document discusses various AOP languages and frameworks, including AspectJ and AspectC++, while introducing essential terminologies like pointcut, join point, and advice. This powerful paradigm thus contributes to more maintainable and scalable software systems. ###
E N D
Survey of Aspect-Oriented Programming Neerja Bhatnagar CS 203 Programming Languages Fall 2004
Motivation for AOP • Code continues to grow in size and complexity • Code evolves to become unmodularized, and hence unclean • Application logic gets intermingled with system code • For example, business logic of processing credit card payment intermingled with code that logs the transaction • AOP aims to improve software design and development via separation of concerns
Conventional Logging • Does not utilize aspects • Utilizes java.util.logging import java.util.logging.*; … static Logger logger = Logger.getLogger(“Log”); … public void setEmployeeAddress(String address) { if (name != null) { logger.logp(Level.INFO, “Employee”, “setEmployeeAddress”, “Address Changed”); employeeAddress = address; } } …
import org.aspectj.lang.* import java.util.logging.*; public aspect AspectLog { Logger logger = Logger.getLogger(“Log”); // specify point of execution for // logging. within matches methods pointcut logMethods(): execution(* *.*(..)) && within(AspectLog); // begin logging before reaching // join point before():logMethods() { … } … Java code remains unchanged! public class Employee { public Employee() { … } … setEmployeeAddress(String address) { … } … } Logging with Aspects • Push functionality related to logging into aspect(s) • Application logic remains unchanged.
AOP Languages and Frameworks Languages • AspectJ (Aspects for Java) • AspectC++ (Aspects for C++, may be C) • Weave.NET (Language Independent Aspects) Frameworks • Nanning (for Java) (http://nanning.codehaus.org) • AspectWerkz (for Java) (http://aspectwerkz.codehaus.org) • JBoss (for Java) (http://www.jboss.org) • HyperJ (for Java) (www.research.ibm.com/hyperspace/hyperj) • Others – abc, AspectC#, CLAW, AOP#, AspectDNG
AOP Terminology (Buzzwords) public class Employee { public String employeeName; … public Employee() {…} public void setEmployeeName(String name) { if (name != null) { logger.logp(Level.INFO, "Employee", "setEmployeeName", "Name change"); employeeName = name; } } … } Point Cut Crosscutting concern Join Point
AOP Terminology (Buzzwords), contd. Aspect import org.aspectj.lang.* import java.util.logging.*; public aspectAspectLog { Logger logger = Logger.getLogger(“Log”); // specify point of execution for // logging. within matches methods pointcut logMethods(): execution(* *.*(..)) && within(AspectLog); // code that actually logs … // begin logging before reaching // join point before():logMethods() { … } … Advice