120 likes | 293 Views
Inheritance Anomalies. Synchronization of concurrent objects and inheritance . Key paper: [Matsuoka93] Analysis of Inheritance Anomalies in OOPL.
E N D
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] COM3362 Winter'02
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. COM3362 Winter'02
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. COM3362 Winter'02
When are Inheritance Anomalies found? • Partition of acceptable states (Get2()) • History-only sensitiveness of acceptable states (Gget(), DoubleClick() ) • Modification of acceptable states. (Lock) COM3362 Winter'02
Core behavior Synchronization behavior Other concern- related behavior How does AOP helps? AO program OO program COM3362 Winter'02
LeftClick(); RightClick(); LeftPress(); LeftRelease(); LeftClick(); RightClick(); LeftPress(); LeftRelease(); History-only related behavior Mouse Mouse MouseWDc MouseWDc 2-button 2-button Wheel Wheel 3-button 3-button WheelClick(); WheelRollUp(); WheelRollDown(); WheelClick(); WheelRollUp(); WheelRollDown(); MiddleClick(); MiddleClick(); Double click No inheritance anomalies! COM3362 Winter'02
Double clicks (1) aspect DoubleClick { private String MouseWDc.prevOp; private String MouseWDc.get_prevOp() { return prevOp; } privatevoid 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); } } } COM3362 Winter'02
Double clicks (2) 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 String curr_op = thisJoinPoint.getSignature().toShortString(); if(m.get_prevOp()!=null && m.get_prevOp().equals(curr_op)) { if (curr_op.indexOf("WheelClick")!=-1) System.out.println("Double WheelClick detected"); } else { m.set_prevOp(curr_op); } } } // end of aspect COM3362 Winter'02
Advantages of using AOP • No code tangling caused by synchronization concerns • No inheritance anomalies associated with concurrency ! • Higher level of reusability. COM3362 Winter'02
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 COM3362 Winter'02
Comments • Solutions are very dependent on the parser for the simulation language. • Use AOP design has hardly been used instead of OOP design. COM3362 Winter'02
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 COM3362 Winter'02