Download presentation
Presentation is loading. Please wait.
1
Inheritance Anomalies
Synchronization of concurrent objects and inheritance. Key paper: [Matsuoka93] Analysis of Inheritance Anomalies in OOPL. “When coding a base class (…) the code related to concurrency control cannot be effectively inherited and/or refined in a subclass without non-trivial redefinitions of the methods implementation.” [C. Lopes PhD] Laura Benitez COM3362 Winter'02
2
Separation of core and synchronization behaviors (1)
Synchronization constraint: In a certain state an object can accept only certain methods to maintain its internal integrity. Bounded-Buffer object: Get(): if buffer not empty. Put(): if buffer not full. Laura Benitez COM3362 Winter'02
3
Separation of core and synchronization behaviors (2)
Synchronization code: Portion of code where the synchronization behavior is controlled. It must always be consistent with the synchronization constraint. Laura Benitez COM3362 Winter'02
4
When are Inheritance Anomalies found?
Partition of acceptable states (Get2()) History-only sensitiveness of acceptable states (Gget(), DoubleClick() ) Modification of acceptable states. (Lock) Laura Benitez COM3362 Winter'02
5
How does AOP helps? AO program OO program Core behavior
Synchronization behavior Other concern- related behavior Laura Benitez COM3362 Winter'02
6
Double click No inheritance anomalies! History-only related behavior
Mouse MouseWDc 2-button 3-button Wheel LeftClick(); RightClick(); LeftPress(); LeftRelease(); WheelClick(); WheelRollUp(); WheelRollDown(); MiddleClick(); Mouse MouseWDc 2-button 3-button Wheel LeftClick(); RightClick(); LeftPress(); LeftRelease(); WheelClick(); WheelRollUp(); WheelRollDown(); MiddleClick(); Laura Benitez COM3362 Winter'02
7
Double clicks (1) Laura Benitez COM3362 Winter'02 aspect DoubleClick {
private String MouseWDc.prevOp; private String MouseWDc.get_prevOp() { return prevOp; } private void MouseWDc.set_prevOp(String op) {prevOp=op;} // very specific pointcuts allow us keeping the advice simple pointcut pc(MouseWDc m): (call(* *(..))) && (!call(* get*(..))) && (!call(* set*(..))) && target(m) && !within(DoubleClick); pointcut pcTB(TwoButton m): call(* *Click(..)) && target(m); pointcut pcWM(WheelMouse m): (call(* LeftClick(..)) || call(* WheelClick(..))) && target(m); after(MouseWDc m): pc(m) { // common behavior for doubleclicks String curr_op = thisJoinPoint.getSignature().toShortString(); if(m.get_prevOp()!=null && m.get_prevOp().equals(curr_op)) { if (curr_op.indexOf("LeftClick")!=-1) System.out.println("Double LeftClick detected"); } else { if ((curr_op.indexOf("LeftClick")==-1) && (curr_op.indexOf("RightClick")==-1) && (curr_op.indexOf("WheelClick")==-1)) { m.set_prevOp(curr_op); } Laura Benitez COM3362 Winter'02
8
Double clicks (2) } // end of aspect Laura Benitez COM3362 Winter'02
after (TwoButton m): pcTB(m) { // exclusive behavior for TwoButton Mice String curr_op = thisJoinPoint.getSignature().toShortString(); if(m.get_prevOp()!=null && m.get_prevOp().equals(curr_op)) { if (curr_op.indexOf("RightClick")!=-1) System.out.println("Double RightClick detected"); } else { m.set_prevOp(curr_op); } after (WheelMouse m): pcWM(m) { // exclusive behavior for Wheel Mice if (curr_op.indexOf("WheelClick")!=-1) System.out.println("Double WheelClick detected"); } // end of aspect Laura Benitez COM3362 Winter'02
9
Advantages of using AOP
No code tangling caused by synchronization concerns No inheritance anomalies associated with concurrency ! Higher level of reusability. Laura Benitez COM3362 Winter'02
10
Solutions found DJ Visitor to solve the Mouse problem. Using AspectJ:
Very specific pointcuts => simpler advice. General pointcuts => more elaborated advice Abstract aspects =>higher degree of reusability Too many abstraction levels make code difficult to follow. Open classes => incremental approach Laura Benitez COM3362 Winter'02
11
Comments Solutions are very dependent on the parser for the simulation language. Use AOP design has hardly been used instead of OOP design. Laura Benitez COM3362 Winter'02
12
Summary of best solutions
Building from scratch: Use of AOP design and open classes Using AspectJ: Use abstract aspects for reusability Use fine grained definition of pointcuts Laura Benitez COM3362 Winter'02
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.