Caching: An Optimization Aspect. Part 1a Background: Container/Simple both inherit from Item && Container contains vector of Item. Cache the value of.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Linked Lists Linear collections.
A Brief Introduction to Aspect-Oriented Programming Zhenxiao Yang.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
1 Data Structures CSCI 132, Spring 2014 Lecture 8 Implementing Queues.
Secure Systems Research Group - FAU Aspect Oriented Programming Carlos Oviedo Secure Systems Research Group.
CS 211 Inheritance AAA.
Chapter 8 Inheritance Part 2. © 2004 Pearson Addison-Wesley. All rights reserved8-2 Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Twin A Design Pattern for Modeling Multiple Inheritance Mahmoud ghorbanzadeh.
1 Topic 10 Abstract Classes “I prefer Agassiz in the abstract, rather than in the concrete.”
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
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.
Iterators CS 367 – Introduction to Data Structures.
Abstraction, Inheritance, and Polymorphism in Java.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
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.
Effective C#, Chapter 1: C# Language Elements Last Updated: Fall 2011.
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.
Object Oriented Programming in C++ Chapter 6 Inheritance.
DOMAIN MODEL—PART 4B: SPECIAL ASSOCIATIONS - INHERITANCE BTS430 Systems Analysis and Design using UML.
Inheritance & Dynamic Binding. Class USBFlashDrive We better introduce a new class USMBFlashDrive and save() is defined as a method in that class Computer.
Course Progress Lecture 1 –Java data binding: Basket example: UML class diagram -> class dictionary without tokens-> language design -> class dictionary.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Compsci 201 Recitation 10 Professor Peck Jimmy Wei 11/1/2013.
Coming up: Inheritance
29-July-2002cse Inheritance © 2002 University of Washington1 Inheritance CSE 142, Summer 2002 Computer Programming 1
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,
Interfaces and Polymorphism CS 162 (Summer 2009).
R R R A Brief Introduction to Aspect-Oriented Programming.
CSC142 NN 1 CSC 142 Overriding methods from the Object class: equals, toString.
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
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.
Software Construction Lab 05 Abstraction, Inheritance, and Polymorphism in Java.
Caching: An Optimization Aspect. Class Diagram for Base Item +name : String +check() : int Simple +weight : int +check() : int Container +capacity : int.
Modern Programming Tools And Techniques-I
Lecture 12 Inheritance.
Comments on the “Three Piles” Problem
03/10/14 Inheritance-2.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Object Oriented Analysis and Design
Paul Ammann & Jeff Offutt
null, true, and false are also reserved.
UML & Programming Martin Fowler.
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
A Brief Introduction to Aspect-Oriented Programming
CSE 143 Lecture 27: Advanced List Implementation
searching Concept: Linear search Binary search
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Podcast Ch18b Title: STree Class
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Non-Linear Structures
COMPUTER 2430 Object Oriented Programming and Data Structures I
Chapter 9 Carrano Chapter 10 Small Java
CS 367 – Introduction to Data Structures
Queues: Implemented using Linked Lists
Software Design Lecture : 39.
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
CIS 110: Introduction to computer programming
Presentation transcript:

Caching: An Optimization Aspect

Part 1a 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

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(); }