Chapter 5 Aspect Oriented Programming



Similar documents
Aspect-Oriented Programming

Progress Report Aspect Oriented Programming meets Design Patterns. Academic Programme MSc in Advanced Computer Science. Guillermo Antonio Toro Bayona

Aspect-Oriented Web Development in PHP

Aspect Oriented Programming. with. Spring

Integration of Application Business Logic and Business Rules with DSL and AOP

Integration of Application Business Logic and Business Rules with DSL and AOP

Data Structures Lecture 1

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Remote Pointcut - A Language Construct for Distributed AOP

Coordinated Visualization of Aspect-Oriented Programs

New Generation of Software Development

Generating Aspect Code from UML Models

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

Konzepte objektorientierter Programmierung

Hello World RESTful web service tutorial

Kotrappa Sirbi, Prakash Jayanth Kulkarni

Aspect-oriented Refactoring of a J2EE Framework for Security and Validation Concerns

Langages Orientés Objet Java

AOSD - Enhancing SoC :: INF5120 :: Mansur Ali Abbasi. AOSD :: Aspect Oriented Software Development SoC :: Separation of Concerns

LAB4 Making Classes and Objects

What is a programming language?

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Keywords Aspect-Oriented Modeling, Rule-based graph transformations, Aspect, pointcuts, crosscutting concerns.

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Aspect-Oriented Software Development

Toward Configurable Access Control for. Healthcare Information Systems

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

Java applets. SwIG Jing He

History OOP languages Year Language 1967 Simula Smalltalk

Using an Aspect Oriented Layer in SOA for Enterprise Application Integration

A COMPARISON OF AOP BASED MONITORING TOOLS

Encapsulating Crosscutting Concerns in System Software

Aspectual Mixin Layers

Object-Oriented Programming in Java

On Type Restriction of Around Advice and Aspect Interference

Using UML Behavioral Model to Support Aspect Oriented Model

Introduction to Object-Oriented Programming

Harmless Advice. Daniel S Dantas Princeton University. with David Walker

Composing Concerns with a Framework Approach

How To Combine Feature-Oriented And Aspect-Oriented Programming To Support Software Evolution

Combining Static and Dynamic Impact Analysis for Large-scale Enterprise Systems

C++ INTERVIEW QUESTIONS

Combining Feature-Oriented and Aspect-Oriented Programming to Support Software Evolution

Aspects for Testing Aspects?

Introduction to Java

Aspect Weaving for OSGi. Martin Lippert (akquinet it-agile GmbH)

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

Lab Experience 17. Programming Language Translation

Software Engineering Techniques

On the (un)suitability of Java to be the first programming language

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Chapter 1 Java Program Design and Development

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

Aspect-Oriented Multi-Client Chat Application

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

The Nature and Importance of a Programming Paradigm

Learn Java - The Application Monitor Aspect Pattern

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Scenario-Based Software Architecture for Designing Connectors Framework in Distributed System

The Application Monitor Aspect Pattern

Aspect-oriented software engineering

Getting Started with the Internet Communications Engine

Smalltalk in Enterprise Applications. ESUG Conference 2010 Barcelona

CS 106 Introduction to Computer Science I

How to use the Eclipse IDE for Java Application Development

CONTRASTING ASPECTUAL DECOMPOSITIONS WITH OBJECT- ORIENTED DESIGNS IN CONTEXT-AWARE MOBILE APPLICATIONS

Java Crash Course Part I

Post object-oriented paradigms in software development: a comparative analysis

Java CPD (I) Frans Coenen Department of Computer Science

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Aspect Refactoring Verifier

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

Aspect-Oriented Development of a P2P File Sharing Application

1001ICT Introduction To Programming Lecture Notes

Representing Change by Aspect

J a v a Quiz (Unit 3, Test 0 Practice)

Implementing Application and Network Security using Aspectoriented

Automation of Library (Codes) Development for Content Management System (CMS)

Technion - Computer Science Department - Ph.D. Thesis PHD Using Aspects to Support the Software Process.

Unification of AOP and FOP in Model Driven Development

Eliminating SQL Injection and Cross-Site Scripting With Aspect Oriented Programming

Load balancing using Remote Method Invocation (JAVA RMI)

McGraw-Hill The McGraw-Hill Companies, Inc.,

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Inheritance in Programming Languages

Automated Test Generation for AspectJ Programs

Glossary of Object Oriented Terms

ARM-BASED PERFORMANCE MONITORING FOR THE ECLIPSE PLATFORM

Tutorial on Writing Modular Programs in Scala

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Lab 1A. Create a simple Java application using JBuilder. Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2.

More on Objects and Classes

Incorporating Aspects into the UML

Crash Course in Java

The Aspect-Oriented Web

A10 Writing Your First Application

Building Robots with NXT and LEJOS. Introduc<on. What is the NXT Robot Michael Wooldridge liv.ac.uk)

Transcription:

2I1AC3 : Génie logiciel et Patrons de conception Chapter 5 Aspect Oriented Programming J'ai toujours rêvé d'un ordinateur qui soit aussi facile à utiliser qu'un téléphone. Mon rêve s'est réalisé. Je ne sais plus comment utiliser mon téléphone Bjarne Stroustrup Régis Clouard regis.clouard @ ensicaen.fr ENSICAEN 14050 Caen

Introduction 2 OOP limitations Code redundancy Code tangling mix-up of multiple concerns at one place Code scattering a concern is scattered over many places Cross-cutting a concern than spans multiple units of OO modularity cannot be implemented without code-tangling and codescattering

Cross-cutting 3 Class A Class B Class C Action1 Action1 Action 2 Action 1 Action2 Action1 Example : Functional Integrity Constraint

Code-scattering 4 Class A Class B Class C call method 1 definition method 1 call method 2 call mthod 2 definition method 2 call method 1 call method 2 Example: Data Persistence

Solutions 5 Respect design principles of Chapter 1! Aspect oriented Programming Gregor Kiczales en 1996 à Xerox PARC Inspiration: Artificial Intelligence Object language Meta-programming Reflection New programming paradigm Software programming history Procedural paradigm OOP paradigm OAP paradigm Separates business concerns from crosscutting concerns

Aspect Oriented Programming 6 OOP without aspect OOP with aspect Class A Class B Class C Class A Class B Class C Aspect

Definitions 7 Aspect Unit of modularity. Can contain fields and methods like a regular Java class. Joint Point Places where crosscutting concerns can be woven in. Ex. method call, field access, object creation. Pointcut Declaration that selects join points and collects contexts at that point (regular expressions) Code Advice Code to be executed at a join point.

Illustration 8 Object program Aspect program Class A Class B Class C Joint Point A1 Joint Point B1 Joint Point C1 Aspect Pointcut1(A1,A2,B1,C2) Pointcut2(A3,B2,C1,C2) Joint Point A2 Joint Point A3 Joint Point B2 Joint Point C2 Pointcut1 Code advice 1 Pointcut1 & Pointcut2 Code advice 2

Joint point models 9 public class HelloWorld { Method call private int max=10; public static void main(string args[]) { new HelloWorld().affichage(); public void affichage() { for (int i=0;i<max;i++) { try { System.out.println("HelloWorld!"); catch (Exception e) { max--; System.err.println("Problème d'affichage");

Joint point models 10 public class HelloWorld { Exception private int max=10; public static void main(string args[]) { new HelloWorld().affichage(); public void affichage() { for (int i=0;i<max;i++) { try { System.out.println("HelloWorld!"); catch (Exception e) { max--; System.err.println("Problème d'affichage");

Joint point models 11 public class HelloWorld { Constructor call private int max=10; public static void main(string args[]) { new HelloWorld().affichage(); public void affichage() { for (int i=0;i<max;i++) { try { System.out.println("HelloWorld!"); catch (Exception e) { max--; System.err.println("Problème d'affichage");

Joint point models 12 public class HelloWorld { Field access private int max=10; public static void main(string args[]) { new HelloWorld().affichage(); public void affichage() { for (int i=0;i<max;i++) { try { System.out.println("HelloWorld!"); catch (Exception e) { max--; System.err.println("Problème d'affichage");

Code Advice 13 Code advice is a method like construct that expresses the action to be taken at the join points that are captured by a pointcut. Before advice executes prior to the join point After advice executes following the join point Around advice In such code advice, the keyword 'proceed' is used to specify where to insert the join point s execution can continue original execution, bypass execution or cause execution with an altered context can cause execution of the join point multiple times

Weaving 14 An OAP application Set of classes Set of aspects Weaving Weaving rules specify how to integrate the final system

Types of weaver 15 1/ Static weaver Source to source translation. Aspect code Class code Weaver Intermediate source code Compiler bytecode

Types of weaver 16 2/ Dynamic weaver Bytecode enhancement, first compile source with original compiler, then weave aspects into class files. Weaver Determine if a code advice must be executed Class code Pre-Weaver modifies the class code Modifier class code Virtual Machine Bytecode

AOP paradigm 17 Separation functional / non functional parts Functional part: business concerns eg, Add or delete an employee Non functional part: crosscutting concerns eg, Security and access control

Examples 18 AspectJ (Open Source) Static weaver URL AspectJ http://www.eclipse.org/aspectj Plug-in Eclipse http://eclipse.org/ajdt

Example 1: HelloWorld (before 19 weaving) Hello.java World.aj public class Hello { public static void main(string a[]){ new Hello().sayHello(); public aspect World { pointcut salutation() : execution (*Hello.sayHello(..)); public void sayhello() { System.out.println("Hello!"); after() :salutation() { System.out.println("Salut à toi aussi");

Example 1: HelloWorld (after 20 weaving) Hello.java World.aj public class Hello { public aspect World { public static void main(string a[]) { new Hello().sayHello(); System.out.println("Salut à toi aussi"); public void sayhello() { System.out.println("Hello!"); pointcut salutation() :execution (*Hello.sayHello(..)); after() :salutation() { System.out.println("Salut à toi aussi");

Example 2: Debug (before 21 weaving) Example2.java Debug.aj public class Exemple2 { private int _x=0; public static void main(string args){ public aspect Debug { pointcut methodex2() : execution(*exemple2.*(..)); for (int i=0;i<10;i++) { Exemple2.increment(); pointcut CallIncr() : execution(*increment(..)); pointcut Ensemble() : public void increment() { methodex2() & CallIncr(); _x++; around() :Ensemble() { System.out.println(x); proceed System.out.println(x);

Example 2: Debug (after 22 weaving) Example2.java After weaving public class Exemple2 { private int _x=0; public static void main(string a[]){ Debug.aj Before weaving public aspect Debug { pointcut methodex2() : execution(*exemple2.*(..)); for (int i=0;i<10;i++){ System.out.println(_x); Exemple2.increment(); System.out.println(_x); pointcut CallIncr() : execution(*increment(..)); pointcut Ensemble() : methodex2() & CallIncr(); public void increment() { _x++; around() :Ensemble() { System.out.println(_x); proceed System.out.println(_x);

Example 3: Design Pattern 23 revisited Singleton OOP : Drawbacks Use of non classical constructor Restrict inheritance Singleton AOP Add a joint point cut on the constructor An attribute stores the instance reference The code advice returns a new instance (1 st call) or the attribute reference

Conclusion 24 OOP + AOP = OOP AOP is available as extensions of many programming languages Java C++ Php C# D Smalltalk The future of programming?