Towards Design – Entity / Relationship Models Richard Hopkins rph@nesc.ac.uk UML for Use Cases NeSC, Edinburgh, Jan 5/6 2006 Contents Goal An appreciation of how UML class diagrams can be used to elucidate technical detail Contents Internal vs External class diagrams Details of class diagrams Practical UML for Use Cases, Jan 5/6 2006 Towards Design 2 Development Process Capture Requirements to elucidate requirements – what entities exist Activity Diag. and how each Class Diag. behaves Partially articulated requirements Use Case Diag. Requirements Sequence Diag. Construct Model of Overall system Class Diag. … Activity Diag. Sequence Diag. Structure Behaviour Requirements level Class Diagram – externally visible entities Design level Class Diagram – model of external entities + internal entities => OO design UML for Use Cases, Jan 5/6 2006 Towards Design 3 Internal vs External User Item has out Student Staff Member Copy Is copy of Is part of contains Journal Book Article has out Ordered print-off User Student to of Loan Staff for print-off order Lendable Journal Copy in of of Article Book Similarities – used external classes as starting point; differences, e.g. A “lendable” entity is may be a more useful abstraction than “Item” – greater commonality but need additional constraints for User-to-Loan UML for Use Cases, Jan 5/6 2006 Towards Design 4 Internal vs External User Item has out Student Staff Member Copy Is copy of Is part of contains Journal Book Article has out Ordered print-off User Student to of Loan Staff for print-off order Lendable Journal Copy in of of Article Book Similarities – used external classes as starting point; differences, e.g. Relationship entities – need information about the relationship – when the loan is to be returned In this case, 1:N, could put that info with the Copy UML for Use Cases, Jan 5/6 2006 Towards Design 5 Internal Entities Introduce Modelling of required internal state need to keep track of fines – what for how much paid Fine Payment Overdue User Student to Loan Staff for print-off order Damage of Loss Lendable Journal in of of Article UML for Use Cases, Jan 5/6 2006 Copy Towards Design Book 6 Contents Goal An appreciation of how UML class diagrams can be used to elucidate techniocal detail Contents Internal vs External class diagrams Details of class diagrams Practical UML for Use Cases, Jan 5/6 2006 Towards Design 7 Aggregation and Composition Journal Article composition Author general aggregation Special Associations Aggregation – To model a collection of things Journal has a collection of Articles Article has a collection of Authors Composition A special case of aggregation – “ownership” / “component” An article is a component of a journal Part can only belong to one whole The part cannot exist without the whole Role name - Not given explicitly – implicit in the end-point – “is part of” Multiplicity – by default (1) --- (0..*) UML for Use Cases, Jan 5/6 2006 Towards Design 8 Multiplicity 1..* Fine 0..* Payment Overdue 1 1 Loan User Student Staff 1 Damage Loss 1 1 1 1 Lendable 1 print-off 0..* order Journal Copy Article Book 1..* Compactly communicates a lot of properties/assumptions – one picture of whole design A payment can relate to several fines An article can’t be in more than one Journal (issue) …. Can be very useful as reality check on requirements with user Can daunting notation for user – may be better to extract all assumptions made! UML for Use Cases, Jan 5/6 2006 Towards Design 9 Attributes Copy Book Title : String ShelfMark : Int of IsCopyOf : Book Title : String Attribute – Information associated with each instance of class Each attribute will have a type (could be omitted) Attributes are inherited – Title would be attribute of book, not Copy Show What’s important for understanding Maybe not all that exists in implementation Don’t show IsCopyof attribute because duplicates Of association Could put in virtual information Title for copy even though only held for Book - ? UML for Use Cases, Jan 5/6 2006 Towards Design 10 Specialised Class vs Attribute Vs. Book Book hardBack: bool HardBackBook SoftBackBook Use specialised class if a significant difference to user, e.g. hardBack has a reBind operation, but softBack doesn’t UML for Use Cases, Jan 5/6 2006 Towards Design 11 Navigability Is copy of of Copy Copy Book One-way from copy to the Book it is a copy of Book Two-way Also From a Book to any of its copies Arrow-head means the association can be followed in the direction shown In implementation view, navigability requires attributes to hold the link(s) to associated object(s) In VP-UML – default is no navigability signs – either both un-specified or both navigable UML for Use Cases, Jan 5/6 2006 Towards Design 12 Complex Class Structures Class Diagram 0..* Book by 0..* 1..* Author 1..* 1 Division 1 by 0..* Part 0..* contains Chapter The intended structure would be elucidated by giving some examples ! Particularly if audience is not familiar with this particular view on the possible structure of book So illustrate the class diagram by one or more instance diagrams UML for Use Cases, Jan 5/6 2006 Towards Design 13 Object Diagrams Class Diagram 0..* Book by 0..* 1..* Author 1..* 1 Division 1 by An Instance 0..* contains diagram Does not show full range of 0..* Part possibilities Chapter The lines are “links” – instances Object Diagram B1: Book Title: UML & WSDL of associations Can annotate links A1: Author Name: Richard A2: Author Name: Guy C111: Chapter Title: Classes P11: Part Title: UML C112: Chapter Title: Use Cases UML for Use Cases, Jan 5/6 2006 P12: Part Title: WSDL with navigability and role if useful A2: Author Name: David Towards Design 14 Questions ? Can we express/derive full OO design from UML? Yes Additional features operations using UML-defined classes as attribute types visibility interfaces …. ????? UML for Use Cases, Jan 5/6 2006 Towards Design 15 Contents Goal An appreciation of how UML class diagrams can be used to elucidate techniocal detail Contents Internal vs External class diagrams Details of class diagrams Practical UML for Use Cases, Jan 5/6 2006 Towards Design 16 Practical – Entity/ Relationship Model Clarifying technical detail – 1 hour One group member plays role of software developer draft a class diagram for the design the system you have been working on quickly! could be two developers for 4-person group Others play role of clients with the developer – discuss and evolve the detail The point is to explore the potential of these diagrams as communication tool – Not to come up with the ideal design UML for Use Cases, Jan 5/6 2006 Towards Design 17