Presentation is loading. Please wait.

Presentation is loading. Please wait.

IS514Slide 1 IS514 Lecture Week 7 Class Diagrams II.

Similar presentations


Presentation on theme: "IS514Slide 1 IS514 Lecture Week 7 Class Diagrams II."— Presentation transcript:

1 IS514Slide 1 IS514 Lecture Week 7 Class Diagrams II

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

3 IS514Slide 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 IS514Slide 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 IS514Slide 5 Type Two - Association Classes associated with / related to one another Example –Student studies a course Very Commonly used “Default” type of relationship Student Course studies►

6 IS514Slide 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 SeminarGroup Student memberOf ►

7 IS514Slide 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 Seminar Module deliveredFor ►

8 IS514Slide 8 Type Five Inheritance Specialisation / generalisation between two classes Example –Part Time Student is a type of Student StudentPartTimeStudent

9 IS514Slide 9 Creating a Class Diagram Adding relationships Last week we drew a class diagram for a Cinema Update the diagram to include the relationship types

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

11 IS514Slide 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 IS514Slide 12 One Solution SportsUtilitySportsCar SaloonCar CarParts Car Accessories parts accessories

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

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

15 IS514Slide 15 Alternative Naming of relationships Role names can be used instead of relationship names Write role name at either end SquareBoard +theBoard +theSquare

16 IS514Slide 16 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 SquareBoard 164 +theBoard+theSquare 1

17 IS514Slide 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 IS514Slide 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 IS514Slide 19 Exercise Solutions Exercise 1 Exercise 2 What is missing? Relationship names

20 IS514Slide 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 IS514Slide 21 Summary Types of associations –Dependency –Association –Aggregation –Composition –Inheritance Multiplicity Next Week – more class diagrams including –Association Classes –Object Diagrams –Constraints –Visibility


Download ppt "IS514Slide 1 IS514 Lecture Week 7 Class Diagrams II."

Similar presentations


Ads by Google