1 / 21

IS514 Lecture Week 7

IS514 Lecture Week 7. Class Diagrams II. So far. Identifying Classes Attributes Operations How to draw basic class diagrams This week Types of relationships Multiplicity. Relationships. Classes do not exist in isolation It is important to consider how they Interact Relate

tim
Download Presentation

IS514 Lecture Week 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IS514 Lecture Week 7 Class Diagrams II

  2. So far • Identifying • Classes • Attributes • Operations • How to draw basic class diagrams • This week • Types of relationships • Multiplicity

  3. Relationships • Classes do not exist in isolation • It is important to consider how they • Interact • Relate • Tend to be VERBS • Five principal types of relationships

  4. Type One - Dependency • Where one class must know about another • Example: • Prospective student knows of a course • Not commonly used • Used more commonly in design / implementation • Java – import javax.swing.*;

  5. Type Two - Association • Classes associated with / related to one another • Example • Student studies a course • Very Commonly used • “Default” type of relationship studies► Student Course

  6. Type Three - Aggregation • Classes made up of other classes • “Part of” relationship • Objects of classes that can exist in their own right • Example • Student is a member of a seminar group memberOf ► SeminarGroup Student

  7. Type Four - Composition • Class is an integral part of another • “Integral part of” relationship • Object of classes that cannot exist without the other • Example: • Seminar is delivered for a Module deliveredFor ► Module Seminar

  8. PartTimeStudent Student Type Five Inheritance • Specialisation / generalisation between two classes • Example • Part Time Student is a type of Student

  9. Creating a Class DiagramAdding relationships • Last week we drew a class diagram for a Cinema • Update the diagram to include the relationship types

  10. One Solution Film Patron Ticket title name ◄ for of ► producer price age length time certificate film buyTicket() genre seeFilm() ChildPatron AdultPatron

  11. Exercise • A garage sells cars, accessories and car parts. The garage sells sport cars, sports utility vehicles and saloon cars. • In groups of 3-4 spend 5 minutes • Draw the class diagram for this scenario • Include relationships • Include relationship types • Ignore attributes and operations

  12. One Solution accessories parts CarParts Car Accessories SaloonCar SportsUtility SportsCar

  13. Exercise • Consider Checkers game. • Draw the class diagram for it • Include relationships • Include relationship types • Ignore attributes and operations http://www.darkfish.com/checkers/Checkers.html

  14. Exercise Solution Board 1 64 Square BlackSquare WhiteSquare On Square Checker WhiteChe cker RedChecker

  15. Alternative Naming of relationships • Role names can be used instead of relationship names • Write role name at either end +theBoard +theSquare Board Square

  16. +theBoard +theSquare Board Square 1 1 64 Multiplicity • Relationships have a multiplicity • Documents how many instances of a class may be associated with instances of another class • Numbers placed on relationship to denote • Minimum • Maximum

  17. Multiplicity • using multiplicity we can specify :- • an exact number simply by writing it • a range of numbers using two dots between a pair of numbers • an arbitrary, unspecified number using a *

  18. Exercise • Example 1 • A Student takes up to six Modules where at most 25 Students can be enrolled on each Module. A Student must study at least one Module. Modules will not run if less than 12 Students study them. • Example 2 • An Order has to come from a single Customer and a Customer may make several Orders over time. Each of these Orders has several Order Lines, each of which refers to a single Product.

  19. Exercise Solutions Exercise 1 Exercise 2 What is missing? Relationship names

  20. This weeks reading ESSENTIAL READING Dennis A, Wixom B, and Tegarden D (2005) System Analysis and Design with UML version 2 second edition, Wiley Chapter 7 Further reading Bennett, S., McRobb, S. and Farmer, R. (2002) Object-Oriented Systems Analysis and Design using UML, 2nd Edition, McGraw-Hill Pages 168-176 http://www.agilemodeling.com/artifacts/classDiagram.htm http://www.omg.org

  21. Summary • Types of associations • Dependency • Association • Aggregation • Composition • Inheritance • Multiplicity • Next Week – more class diagrams including • Association Classes • Object Diagrams • Constraints • Visibility

More Related