210 likes | 285 Views
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
E N D
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 • Tend to be VERBS • Five principal types of relationships
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.*;
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
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
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
PartTimeStudent Student Type Five Inheritance • Specialisation / generalisation between two classes • Example • Part Time Student is a type of Student
Creating a Class DiagramAdding relationships • Last week we drew a class diagram for a Cinema • Update the diagram to include the relationship types
One Solution Film Patron Ticket title name ◄ for of ► producer price age length time certificate film buyTicket() genre seeFilm() ChildPatron AdultPatron
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
One Solution accessories parts CarParts Car Accessories SaloonCar SportsUtility SportsCar
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
Exercise Solution Board 1 64 Square BlackSquare WhiteSquare On Square Checker WhiteChe cker RedChecker
Alternative Naming of relationships • Role names can be used instead of relationship names • Write role name at either end +theBoard +theSquare Board Square
+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
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 *
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.
Exercise Solutions Exercise 1 Exercise 2 What is missing? Relationship names
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
Summary • Types of associations • Dependency • Association • Aggregation • Composition • Inheritance • Multiplicity • Next Week – more class diagrams including • Association Classes • Object Diagrams • Constraints • Visibility