Caching: An Optimization Aspect. Class Diagram for Base Item +name : String +check() : int Simple +weight : int +check() : int Container +capacity : int.

Slides:



Advertisements
Similar presentations
A Brief Introduction to Aspect-Oriented Programming Zhenxiao Yang.
Advertisements

Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Secure Systems Research Group - FAU Aspect Oriented Programming Carlos Oviedo Secure Systems Research Group.
CS 211 Inheritance AAA.
Inheritance Inheritance Reserved word protected Reserved word super
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Topic 10 Abstract Classes “I prefer Agassiz in the abstract, rather than in the concrete.”
Abstract Classes and Interfaces
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
1)Never start coding unless you understand the task! 2)Gather requirements first. This means identify the problem and ask questions about it. Now you kind.
A Formal Model of Modularity in Aspect-Oriented Programming Jonathan Aldrich : Objects and Aspects Carnegie Mellon University.
Iterators CS 367 – Introduction to Data Structures.
2.5 OOP Principles Part 1 academy.zariba.com 1. Lecture Content 1.Fundamental Principles of OOP 2.Inheritance 3.Abstraction 4.Encapsulation 2.
Abstraction, Inheritance, and Polymorphism in Java.
Outline Introduction Problem Statement Object-Oriented Design Aspect-Oriented Design Conclusion Demo.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Inheritance. Recall the plant that we defined earlier… class Plant { public: Plant( double theHeight ) : hasLeaves( true ), height (theHeight) { } Plant(
Developing Adaptive J2ME Applications Using AspectJ Ayla Débora and Paulo Borba {add, Centro de Informática - UFPE.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
CS 2430 Day 9. Announcements Quiz on Friday, 9/28 Prog1: see , see me as soon as possible with questions/concerns Prog2: do not add any public methods.
Lecture 8: Object-Oriented Design. 8-2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Objectives “Good object-oriented programming is really.
CS 11 java track: lecture 4 This week: arrays interfaces listener classes inner classes GUI callbacks.
Aspect Oriented Programming Gülşah KARADUMAN.
Effective C#, Chapter 1: C# Language Elements Last Updated: Fall 2011.
Test Isolation and Mocking Technion – Institute of Technology Author: Gal Lalouche © 1 Author: Gal Lalouche - Technion 2015 ©
1 Abstract Classes “I prefer Agassiz in the abstract, rather than in the concrete.” CS Computer Science II.
Mohammed Al-Dhelaan CSci 253 Object Oriented Design Instructor: Brad Taylor 06/02/2009 Factory Method Pattern.
DOMAIN MODEL—PART 4B: SPECIAL ASSOCIATIONS - INHERITANCE BTS430 Systems Analysis and Design using UML.
Inter-Type Declarations in AspectJ Awais Rashid Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
Course Progress Lecture 1 –Java data binding: Basket example: UML class diagram -> class dictionary without tokens-> language design -> class dictionary.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Applying Translucid Contracts for Modular Reasoning about Aspect and Object Oriented Events Mehdi Bagherzadeh Gary T. Leavens Robert Dyer Foundations of.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
Coming up: Inheritance
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Inheritance Type/Subtype Relationship. Inheritance Idea: An object B of one type, termed child class, inherits from another object A of another type,
R R R A Brief Introduction to Aspect-Oriented Programming.
AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
CSC142 NN 1 CSC 142 Overriding methods from the Object class: equals, toString.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Caching: An Optimization Aspect. Part 1a Background: Container/Simple both inherit from Item && Container contains vector of Item. Cache the value of.
Collections Dwight Deugo Nesa Matic
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Software Construction Lab 05 Abstraction, Inheritance, and Polymorphism in Java.
Inheritance Class Hierarchies SoftUni Team Technical Trainers Software University
Modern Programming Tools And Techniques-I
Lecture 12 Inheritance.
03/10/14 Inheritance-2.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Object Oriented Analysis and Design
null, true, and false are also reserved.
A Brief Introduction to Aspect-Oriented Programming
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Building Java Programs
CSE 373 Data Structures and Algorithms
Podcast Ch18b Title: STree Class
Example: LinkedSet<T>
Software Design Lecture : 12.
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Chapter 9 Carrano Chapter 10 Small Java
Software Design Lecture : 39.
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
CIS 110: Introduction to computer programming
Presentation transcript:

Caching: An Optimization Aspect

Class Diagram for Base Item +name : String +check() : int Simple +weight : int +check() : int Container +capacity : int +check() : int +addItem(Item it):void contains 0..* Back Item Target Container Source Caching Container C

Background Container/Simple both inherit from Item && Container contains vector of Item. Cache the value of the sum for each container and the number of violations. If the same container is checked again and there has been no change, we can reuse the cached values

Caching Aspect Interface C (view it as a role) –Can have one of its methods cached –Requires a method allInvalidated: Returns all objects whose caches would be invalidated by a modification to the current object AspectJ interfaces can provide member implementations and fields: field cachedValue And method clearCache(){…} –Very useful! Define popular behaviors.

Reusable Use abstract pointcuts to represent the methods to be cached (cachedmeth) and the methods to invalidate caches (invalidate). Advice for those pointcuts.

Object Object around(..) : cachedmeth … Object cachedValue

Back Aspect Want to maintain an invariant. Intercept calls that can affect the invariant.

Old viewgraphs Alternative solution

HashTable method Hashtable cache=new Hashtable(); pointcut changed(Container c):target(c) && call(* Container.addItem(..)); before(Container c):changed(c){ if(cache.containsKey(c)){ Container contain=c.getContainer(); cache.remove(c); //invalidate while(contain!=null) { cache.remove(contain); contain=contain.getContainer();

pointcut getvalue(Item i):target(i) && call(* *.check(..)); int around(Item i):getvalue(i){ if(cache.containsKey(i)) return ((Integer)cache.get(i)).intValue(); int v=thisJoinPoint.proceed(i); cache.put(i,new Integer(v)); return v;

Introductions private int Container.violations = 0; private int Container.total = 0; private boolean Container.cacheIsValid = false;

pointcut getTotal(Container c): call (int check(..)) && target(c); int around (Container c): getTotal(c){ if(c.cacheIsValid){ System.out.println(c.name + " using cached value for total: " + c.total); if(c.violations > 0){ System.out.println(c.name + " had " + c.violations + " violations"); return c.total; } else return proceed(c);

after(Container c) returning (int tot): getTotal(c){ c.total = tot; c.violations = c.total - c.capacity; c.cacheIsValid = true;}

Adding a new item: pointcut newItem(Container c, Item i): call(void setContainer(..)) && target(i) && args(c); after(Container c, Item i): newItem(c, i){ c.setValid(false); } public void Container.setValid(boolean isValid){ cacheIsValid = isValid; if(getContainer() != null){ getContainer().setValid(isValid);

What was learned? The Hashtable allows us to better encapsulate the Caching aspect, leaving us with more elegant code that doesn’t pollute the name-space of Container It seems cleaner for each Container to keep track of its total weight. This will also probably shorten the run-time.

Part 1b/d: Improving modularity and reusability If we don’t cache, we don’t need the back pointers in our containers. So make it an aspect! Improve reusability through use of abstract aspects.

Back pointer: based on introductions private Container Item.container; public void Item.setContainer(Container c){ container = c;} public Container Item.getContainer(){ return container;}

Setting the BP pointcut addingItem(Container c, Item i): call (void addItem(..)) && target(c) && args(i); after(Container c, Item i): addingItem(c, i){ i.setContainer(c); }

Abstract Caching Aspect There is a Parent/Child relationship which can be useful in creating abstract aspects. interface Parent extends Child{ void addItem(Child c); abstract aspect Cashing{ abstract pointcut invalidate(Parent p); abstract pointcut cashing(Parent p);

Such that we can implement interesting functionality based only on knowledge that a Parent/Child relationship exists. after(Parent p): invalidate(p){ while(p != null){ beforeInvalidate(p); p.cashedValue = -1; p = ((Child)p).getParent(); }