9. Dominant Decomposition: Organizational Hard to calculate salary... Easy to find out supervisor relationships... Employee Research ResearchManager Sales SalesManager Financial FinancialManager Support SupportManager
10. Dominant Decomposition: Payroll Easy to calculate salary... Hard to find out supervisor relationships... Employee HourlyWage MonthlyWage Research Regular Sales SalesManager RegularManager Secretary Labourer ResearchManager
11. Crosscutting Concerns source: http://www.ercim.org/publication/Ercim_News/enw58/van_deursen1.jpg Column: Module Each Color: Task
12. Modularizing Crosscutting Concerns MDSOC approaches deal with the modularization of crosscutting concerns . tangling / scattering extra module (e.g., aspect, layer, ...) modularized code (e.g., advice, ...) join points Now somehow make all modules work together...
13.
14.
15.
16.
17. Basic Modularization Operations // CaesarJ-like pseudo code class C { void f() { ... } void g() { ... } void h() { ... } } class A { before(): execution(void C.f()) { ... } after(): execution(void C.g()) { ... } void around(): execution(void C.h()) { ... proceed(); ... } } ... deploy(new A()); ... actual-C f = ( ... ) g = ( ... ) h = ( ... ) C instance-of-C actual-instance-of-C A-proxy f = ( ...; resend ) g = ( resend; ... ) h = ( ...; resend; ... ) f
18. Instance-Local Deployment // CaesarJ-like pseudo code class C { void f() { ... } void g() { ... } void h() { ... } } class A { before(): execution(void C.f()) { ... } after(): execution(void C.g()) { ... } void around(): execution(void C.h()) { ... proceed(); ... } } ... deploy(new A(), instance-of-C); ... actual-C f = ( ... ) g = ( ... ) h = ( ... ) C instance-of-C actual-instance-of-C A-proxy f = ( ...; resend ) g = ( resend; ... ) h = ( ...; resend; ... )
19. Thread-Local Deployment // CaesarJ-like pseudo code class C { void f() { ... } void g() { ... } void h() { ... } } class A { before(): execution(void C.f()) { ... } after(): execution(void C.g()) { ... } void around(): execution(void C.h()) { ... proceed(); ... } } // in thread T1 ... deploy(new A()) { ... } ... actual-C f = ( ... ) g = ( ... ) h = ( ... ) C instance-of-C actual-instance-of-C A-proxy f = ( ...; resend ) g = ( resend; ... ) h = ( ...; resend; ... ) the delegate of C is a function of the thread T1 others
20. cflow: Continuous Weaving // CaesarJ-like pseudo code class C { void f() { ... } void g() { ... f(); ... } } class A { before(): execution(void C.f()) && cflow(execution(void C.g())) { ... } } ... deploy(new A()); ... actual-C f = ( ... ) g = ( ... f(); ... ) C instance-of-C actual-instance-of-C // in thread T1 ... instance-of-C.g(); ... T1 others A-cw-proxy g = ( act-cflow; resend; deact-cflow ) A-proxy f = ( ...; resend ) f g
21. Introduction // CaesarJ-like pseudo code class C { int x; void f() { ... } } class A { int C.y; void C.g() { ... } before(): execution(void C.f()) { ... } } ... deploy(new A()); ... actual-C f = ( ... ) C instance1-of-C actual-instance1-of-C x = 23 ... instance1-of-C.y ... instance2-of-C actual-instance2-of-C x = 42 A-int-proxy y = ( /* add y field to instance */; self y ) g = ( /* imp. of introduced method */ ) y A-int1-proxy y = 0
22.
23. j – Object-Oriented Programming [Skipper04] class Subject ext Object { Integer attr Observer obs void doSomething(Object x) { this.attr := 25 } void changed(Object x) { this.obs.update(this) } void setObserver(Observer x) { this.obs := x } } class Observer ext Object { void update(Subject x) { out.println(x.attr) } } class Main ext Object { Subject s Observer o void main(Main x) { x.s := new Subject; x.o := new Observer; x.s.setObserver(x.o); x.s.doSomething(null); x.s.changed(null) } }
24. j Prepared Heap Subject_prototype attr obs Subject_proxy Subject doSomething = (...) changed = (...) setObserver = (...) Main_prototype s o Main_proxy Main main = (...) Observer_prototype Observer_proxy Observer update = (...) Object proxy Object
25. j Class Instantiation doSomething Subject_prototype attr obs Subject_proxy Subject doSomething = (...) changed = (...) setObserver = (...) Main_prototype s o Main_proxy Main main = (...) Observer_prototype Observer_proxy Observer update = (...) Object proxy Object subject_inst attr obs subj_inst_proxy
26. ij – Inter-Type Declarations [Skipper04] class Observer ext Object { void update(Subject x) { out.println(x.attr) } Subject <-- Observer obs Subject <-- void changed(Object x) { this.obs.update(this) } Subject <-- void setObserver(Observer x) { this.obs := x } } class Subject ext Object { Integer attr void doSomething(Object x) { this.attr := 25 } } class Main ext Object { Subject s Observer o void main(Main x) { x.s := new Subject; x.o := new Observer; x.s.setObserver(x.o); x.s.doSomething(null); x.s.changed(null) } }
27. ij Prepared Heap Subject_proto attr Subject_proxy Subject doSomething = (...) Main_proto s o Main_proxy Main main = (...) Observer_proto Observer_proxy Observer update = (...) Object proxy Object intr_proxy 1 changed = (...) setObserver = (...) obs=(... self obs)
28. ij Class Instantiation obs Subject_proto attr Subject_proxy Subject doSomething = (...) Main_proto s o Main_proxy Main main = (...) Observer_proto Observer_proxy Observer update = (...) Object proxy Object intr_proxy 1 changed = (...) setObserver = (...) obs=(... self obs) subject_inst attr subj_inst_proxy intr_proxy2 obs
29. aj – Pointcut and Advice AOP [Skipper04] class Subject ext Object { Integer attr void changed(Object x) { out.println(this.attr) } } aspect Observer { bool changed before set (Integer Subject.attr) { this.changed := v.neq(r.attr) } after set (Integer Subject.attr) { if (this.changed){ r.changed(null) } else { null } } } class Main ext Object { Subject s void main(Main x) { x.s := new Subject; x.s.attr := 25; } }