Download presentation
Presentation is loading. Please wait.
Published byHilary Marsh Modified over 9 years ago
1
Relationship Aspects David J. Pearce and James Noble Victoria University of Wellington, New Zealand
2
COMP205 Software Design and Engineering What are Relationships? Relationships: –Essentially same as “associations” in UML –Provide Navigability –Correspond to several possible implementations –Relationship implementation typically tangled amongst participants Student name age ** Attends Course title code workload
3
COMP205 Software Design and Engineering How is this implemented? Implementation #1 – embedded fields –Insert collections into either/or both participants –Participants provide interface for manipulating relationship –Code for implementing relationship tangled –Student and Course are tightly coupled Set attends Student name age ** Attends Course title code workload Set attends
4
COMP205 Software Design and Engineering Attends How is this implemented? Implementation #2 – Map –Participants not modified! –External Map(s) used instead –Code manipulating relationship also external –Relationship is more modular here Student name age ** Course title code workload Attends Map >
5
COMP205 Software Design and Engineering What are Relationships? Trade-offs: –Embedded field approach Fast – constant-time access to relationship data Storage always consumed by participant instances Relationship code intermingled with class code –Map approach Slower, using Map lookup (e.g. HashMap, Red-Black Tree) Storage used only for objects actively involved Relationship interface centralised Relationship Reuse –Relationship code cannot easily be reused –Changing between two approaches non-trivial
6
COMP205 Software Design and Engineering What are Relationships? Trade-offs: –Embedded field approach Fast – constant-time access to relationship data Storage always consumed by participant instances Relationship code intermingled with class code –Map approach Slower, using Map lookup (e.g. HashMap, Red-Black Tree) Storage used only for objects actively involved Relationship interface centralised Relationship Reuse –Relationship code cannot easily be reused –Changing between two approaches non-trivial Relationship Aspects bring these approaches together!
7
COMP205 Software Design and Engineering Relationship Aspects Student name age Course title code workload > StaticRel > Attends FROM=Student TO=Course
8
COMP205 Software Design and Engineering Relationship Aspects Student name age Course title code workload > StaticRel > Attends FROM=Student TO=Course Weaver > StaticRel > Attends FROM=Student TO=Course Student name age Course title code workload Set
9
COMP205 Software Design and Engineering Relationship Aspects Student name age Course title code workload > HashRel > Attends FROM=Student TO=Course Weaver > HashRel > Attends FROM=Student TO=Course Student name age Course title code workload
10
COMP205 Software Design and Engineering Generic Aspects Targets generic parameters! public abstract aspect StaticRel implements Relationship { public interface Fwd {} public interface Bwd {} declare parents : TO implements Bwd; declare parents : FROM implements Fwd; private HashSet Fwd.fwd = new HashSet (); private HashSet Bwd.bwd = new HashSet (); … }
11
COMP205 Software Design and Engineering Generic Aspects StaticRel declare parents: TO implements Bwd; declare parents: FROM implements Fwd; Attends StaticRel declare parents: Course implements Bwd; declare parents: Student implements Fwd; StaticRel declare parents: Student implements Bwd; declare parents: Faculty implements Fwd; Supervises
12
COMP205 Software Design and Engineering An Issue with Generic Aspects Cannot have multiple StaticRels with same FROM or TO type –Because of name clash with fields inserted by AspectJ Workaround –Provide multiple identical StaticRels –Then a type can appear in FROM or TO position multiple times
13
COMP205 Software Design and Engineering Relationship Interface interface Relationship { public void add(FROM,TO); public void remove(FROM,TO); public Set to(TO t); public Set from(FROM f); … }
14
COMP205 Software Design and Engineering Relationship Polymorphism Code unaware of relationship implementation –This is hard to achieve with OOP! –Relationship interface makes this easy int count(Student s, Relationship r){ int total=0; for(Course c : r.from(s)) { total++; } return total; } class Attends1 extends StaticRel ; class Attends2 extends HashRel ; … = count(Attends1.aspectOf()); … = count(new Attends2());
15
COMP205 Software Design and Engineering Reflexive Relationships Reflexive if FROM = TO –Many operations apply only to reflexive relationships –E.g. transitive closure, cycle detection, shortest paths … City name … * * city
16
COMP205 Software Design and Engineering Performance – Students/Courses Student-Course Benchmark –20,000 courses, 100,000 students –500,000 random enrolments –Then, tight loop traversing relationship
17
COMP205 Software Design and Engineering Performance – Road Network Road Network –Cities connected together by roads –100 cities, 5000 randomly generated roads –Compute all-pairs shortest paths
18
COMP205 Software Design and Engineering Relationship Aspect Library (RAL) –Library of Relationship Aspects –Written in Java/AspectJ –Provides StaticRel, HashRel + many more … www.mcs.vuw.ac.nz/~djp/RAL
19
COMP205 Software Design and Engineering Conclusion Traditional Relationships in OOP –Suffer from code tangled in participants –Difficult to switch between implementations –Difficult to reuse relationship management code Relationship Aspects –Unify different approaches to implementation relationships –Provide well-defined interface –Give proper abstraction of implementation from interface
20
COMP205 Software Design and Engineering Attends What are Relationships? Relationships as pairs : –Fixed FROM and TO position –E.g. Attends –NOT Attends Student name age Course title code **
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.