SE 510 Principles and Applications of Software Design Aspect Oriented Programming October 5, 2005 Jeff Webb.

Slides:



Advertisements
Similar presentations
4. Object-Oriented Programming Procedural programming Structs and objects Object-oriented programming Concepts and terminology Related keywords.
Advertisements

Programming Paradigms and languages
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
1 JAC : Aspect Oriented Programming in Java An article review by Yuval Nir and Limor Lahiani.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development.
October - December 2013CSC5021: The Problem With Aspects (J P Gibson)1 The Problem With Aspects (AOP) A style of programming that attempts to abstract.
ASPECT ORIENTED SOFTWARE DEVELOPMENT Prepared By: Ebru Doğan.
Object-oriented Programming Concepts
Software Lifecycle A series of steps through which a software product progresses Lifetimes vary from days to months to years Consists of –people –overall.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Software Issues Derived from Dr. Fawcett’s Slides Phil Pratt-Szeliga Fall 2009.
Generative Programming. Generic vs Generative Generic Programming focuses on representing families of domain concepts Generic Programming focuses on representing.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Language Evaluation Criteria
Outline Introduction Problem Statement Object-Oriented Design Aspect-Oriented Design Conclusion Demo.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Carolyn Seaman University of Maryland, Baltimore County.
INTRODUCTION TO PROGRAMMING STRUCTURE Chapter 4 1.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
O BJECT O RIENTATION F UNDAMENTALS Prepared by: Gunjan Chhabra.
Aspect Oriented Programming (AOP) in.NET Brent Krueger 12/20/13.
Aspect Oriented Programming Razieh Asadi University of Science & Technology Mazandran Babol Aspect Component Based Software Engineering (ACBSE)
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Architectural Styles.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Marie desJardins University of Maryland, Baltimore County.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
CSE 219 Computer Science III Program Design Principles.
Aspect Oriented Programming Gülşah KARADUMAN.
SE: CHAPTER 7 Writing The Program
Generative Programming. Automated Assembly Lines.
Joel Phinney March 31, ◦ Concerns  Separation of Concerns, Tangled and Scattered Concerns, Cross-Cutting Concerns, Aspects ◦ Aspect-Oriented Software.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Andrew S. Budarevsky Adaptive Application Data Management Overview.
Methodology: The AOP Refactoring Process Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton Advisor:
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
Mark Marron 1, Deepak Kapur 2, Manuel Hermenegildo 1 1 Imdea-Software (Spain) 2 University of New Mexico 1.
Software Engineering Principles. SE Principles Principles are statements describing desirable properties of the product and process.
Aspect-Oriented Programming An Introductory Presentation Mike Landi MSCS Candidate Union University.
Dr.Basem Alkazemi
Liang, Introduction to C++ Programming, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 6 Advanced Function Features.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (1/2)
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Introduction to OOP CPS235: Introduction.
Advanced Software Development Karl Lieberherr CSG 260 Fall Semester
Aspect Oriented Security Tim Hollebeek, Ph.D.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
R R R A Brief Introduction to Aspect-Oriented Programming.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (1/2)
Class Design. Class Design The analysis phase determines what the implementation must do, and the system design.
SOFTWARE DESIGN AND ARCHITECTURE
Software Quality Engineering
Object-Orientated Programming
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Algorithms and Problem Solving
Introduction to Data Structure
AspectAda Aspect-Oriented Programming for Ada95
What Is Good Software(Program)?
From Use Cases to Implementation
Presentation transcript:

SE 510 Principles and Applications of Software Design Aspect Oriented Programming October 5, 2005 Jeff Webb

Aspect-Oriented Programming Gregor Kiczales, John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier and John Irwin 1997 Xerox Palo Alto Research Center

Background Information The process of functional decomposition breaks a system down into smaller and smaller parts. –Units of behavior or function. Programming languages provide mechanisms that allow us to define abstractions for these small parts and then compose them into systems.

Generalized Procedure Based Languages Procedural OO Functional

“It feels comfortable to talk about what is encapsulated as a functional unit of the overall system”. ……………………….. We will be considering units of decomposition that are not functional.

The Problem There are many programming problems for which neither procedural nor object-oriented techniques are sufficient to clearly capture some of the important design decisions the program must implement. Examples –Error detection and handling –Security issues –Logging

Without AOP The implementation of those design decisions will be scattered throughout the code, resulting in “tangled code”.

The Problem AOP’s core idea is “separating the business logic in an application from the common services that support it.”

The issues that make these design decisions so hard to clearly capture in code are called ASPECTS The problem is that they CROSS-CUT the systems basic functionality.

Example LISP Image processing functions Some primitive functions are developed and some compound functions Requirements –Easy to develop and maintain –Efficient use of memory

A primitive image function “or!” Public Image or! (Image a, Image b){ Image result = new Image(); For i from 1 to width do{ For j from 1 to height do{ set-pixel (result i j) = or ( (get-pixel a i j) (get-pixel b i j) ); } Return result; }

More functions Functionality Implementation pixelwise logical operations written using loop primitive as or!, and!, not!above. shift image up, down written using loop primitives; slightly different loop structure. difference of two images Function remove! (a b) and!( a (not! b)) top edge of a region Function top-edge! (a) remove!(a (down! a)) bottom edge of a region Function bottom-edge! (a) remove!( a (up! a))

Easy to develop and maintain High level function to return horizontal edge pixels Function horizontal-edge! (a){ Return or! (top-edge!(a) bottom-edge!(a)); }

Hierarchical structure

Not memory efficient Each procedure loops over a number of images Many output images are created frequently, only to be quickly consumed by another loop Results in excessively frequent memory references and storage allocation Leads to cache misses, page faults and terrible performance

Solution to this problem Take a more global approach and hand code the entire process into one, efficient piece of code.

Memory efficient Public Image horizontal-edge! (a){ Image result, a-up, a-down = new Image(); a-up = up!(a); a-down = down!(a); For i from 1 to width do{ For j from 1 to height do{ set-pixel(result i j) = or (and( (get-pixel a i j) (not (get-pixel a-up i j))) and (get-pixel a i j) (not (get-pixel a-down i j)) ) } // j for } // i for Return result; }

Problems Tangled code Difficult to maintain Destroyed the original clear functional structure

Hierarchical structure

Data Flow Diagram and! not! and! or! not! up! a

Memory efficient Public Image horizontal-edge! (a){ Image result, a-up, a-down = new Image(); a-up = up!(a); a-down = down!(a); For i from 1 to width do{ For j from 1 to height do{ set-pixel(result i j) = or (and( (get-pixel a i j) (not (get-pixel a-up i j))) and (get-pixel a i j) (not (get-pixel a-down i j)) ) } // j for } // i for Return result; }

Crux of the problem Two properties are being implemented –1 Functionality –2 Loop fusion ( for the sake of memory ) Both properties originate from primitive filters They must compose differently as filters are composed

Cross-Cutting Functionality composes hierarchically in the traditional way Loop fusion composes by fusing the loops of those primitive filters that : 1.have the same loop structure 2.end up in a producer/consumer relationship at runtime The properties cross-cut one another This cross-cutting phenomena results in the tangled code

Problem with GP languages Only provide one composition mechanism Programmer must do the co-composition manually Leads to complexity and tangling Use two different languages, One for the components and one for the aspects. Solution

Component Can be cleanly encapsulated in a generalized procedure (i.e. object, method, procedure, API) By cleanly, we mean well-localized, and easily accessed and composed as necessary.

Aspect Can not be cleanly encapsulated in a generalized procedure. Aspects tend not to be units of the system’s functional decomposition, but rather to be properties that affect the performance or semantics of the components in systemic ways. Examples of aspects include memory access patterns and synchronization of concurrent objects.

Goal of AOP To support the programmer in cleanly separating components and aspects from each other, by providing mechanisms that make it possible to abstract and compose them to produce the overall system.

Programming with Aspects Rewrite the components so they can be read by the weaver Create an aspect program Weave the two together to produce optimal intermediate code

Component Re-write Public iterater Image pixelwise (Image a, Image b, operator MyOp){ Image result = new Image(); For i from 1 to width do{ For j from 1 to height do{ set-pixel (result i j) = MyOp ( (get-pixel a i j) (get-pixel b i j) ); } Return result; } Function or! (a a){ pixelwise( a b “or”) }

Component weaving Weaver reads the component program and builds a data graph, noting the nodes and edges and! not! and! or! not!

Aspect Language program cond { if (loop-shape(currentNode) == ’pointwise’ and loop-shape(nextNode) == ’pointwise’){ fuse (currentNode, nextNode, ’pointwise’); } // end if } // end cond Where pointwise is an iterator function that takes 2 image parameters and an operator paramater.

Aspect weaving Checks whether two nodes, that are connected by a data flow edge, both have a similar loop structure, and if so it fuses them into a single loop that also has the particular structure, and that has the appropriate merging of the inputs, loop variables and body of the two original loops.

Weaving output Produces an optimally structured C program Note that the real system required about a dozen or so aspects. Program analysis and understanding are to significant for a compiler to be able to use

Results Hand coding the basic functionality of original program required 768 loc (LISP) The hand coded, optimized version implements –Fusion optimization –Memoization of intermediate results –Compile time memory allocation –Specialized intermediate data structures loc The tangled code is extremely difficult to maintain, since small changes to the functionality require mentally untangling and then re-tangling it.

Results Base implementation and three aspect programs = 1039 loc Time efficiency was comparable to hand coded version Space efficiency was better than hand coded version.

Questions ?

References Gregor Kiczales, John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier and John Irwin. Aspect Oriented Programming, Proceedings of the ECOOP, Volume #32, issue 1ess, March 1997, pages Memoization:

Additional Example Person Owns Dog Taken from :

Person Owns Dog class Person attribute numOfDogsOwned simple accessor method getNumDogsOwned() Person numOfDogsOwned GetNumDogsOwned()

Person Owns Dog /** * not a dog in sight... */ public class Person { private String lastName; private Address address;... public String getLastName() { return lastName; }... }

Person Owns Dog /** * not a person in sight... */ public aspect DogOwnership { public interface IDogOwner {}; private int IDogOwner.numDogsOwned; public int IDogOwner.getNumDogsOwned() { return numDogsOwned; }

Person Owns Dog - We want to create a dog-owning person -We could do this by creating a DogOwningPerson class -However dog-owning isn't limited to people -maybe an Organization can own dogs too?

Keep the concept of dog ownership independent of any one kind of dog owner public aspect PersonOwnsDog { declare parents : Person implements DogOwnership.IDogOwner; } - Now, Person and DogOwnership are independently reusable

Now you can call the getNumDogsOwned method on a Person Person person = new Person(); person.getNumDogsOwned();