Presentation is loading. Please wait.

Presentation is loading. Please wait.

IS0514Slide 1 IS0517 Lecture Week 8 Class Diagrams III.

Similar presentations


Presentation on theme: "IS0514Slide 1 IS0517 Lecture Week 8 Class Diagrams III."— Presentation transcript:

1 IS0514Slide 1 IS0517 Lecture Week 8 Class Diagrams III

2 IS0514Slide 2 So far Identifying –Classes Attributes Operations –Types of relationships –Multiplicity How to draw class diagrams This week –Class Diagrams Visibility Association Classes Constraints Recursive relationships –Object Diagrams

3 IS0514Slide 3 Visibility Quick Question: –Are all attributes available to other objects? –Consider the class person –Which attributes should be available? –Which operations should be available? Attributes –Probably many of them are private Operations –Probably most of them are public

4 IS0514Slide 4 Visibility in UML VisibilityDescriptionSymbol PublicIs directly accessible by an instance of any class + PrivateMay only be used by an instance of the class that includes it - ProtectedMay be used either by an instance of the class that includes it or by a subclass of that class # PackageIs directly accessible only by instances of a class in the same package ~ Design Analysis

5 IS0514Slide 5 Examples

6 IS0514Slide 6 Exercise 1 Given the class BankAccount below Identify the visibility of the (i.e., choose + or – ) for: –Attributes –Operations

7 IS0514Slide 7 Exercise 1 – One Answer I would love to be able to set the balance on my account but can I?

8 IS0514Slide 8 Association Classes Sometimes the way in which objects of a class are associated is just as important as the objects of a class themselves Consider the association between Student and Module. Where should our system record the student’s marks on for each student on each module? StudentModule 1..*6 is taking  is taking mark : Integer association class

9 IS0514Slide 9 Exercise 2 – From Seminar A publisher specialises in producing volumes of short stories. Most stories are by one author, but occasionally, two authors collaborate on a story. Stories that have been originally published in one volume may be re-issued in other collections. Whenever a story is used in a volume, various operational details must be recorded. Stories have a title and a genre. Authors have a name and an address. Collections have a title and an introduction. When a story is used in a volume the position in the volume needs to be recorded. Redraw including –Multiplicity –Association Class

10 IS0514Slide 10 Exercise 2 -One Solution  

11 IS0514Slide 11 Constraints a constraint is a condition that has to be satisfied Use with care –Too much text on a diagram –Can be over used Order dateReceived isPrepaid number: String price: Money dispatch() close() Order Line quantity : Integer price : Money isSatisfied : Boolean * line items 1 {if Order.customer.creditRating is “poor”, then Order.isPrepaid must be true} Customer creditRating getCreditRating 1..* 1

12 IS0514Slide 12 Constraints... continued another common situation is when there is an ‘exclusive or’ between two associations CopyBook Journal 1..* is a copy of 0..1 is a copy of 1..* 0..1 CopyBook Journal 1..* is a copy of 0..1 is a copy of 1..* 0..1 {or} under-constrainedUsing an or-constraint

13 IS0514Slide 13 Exercise 3 Consider a car rental company The company will only rent a car to customers over the age of 25 

14 IS0514Slide 14 Exercise 3 – One Solution 

15 IS0514Slide 15 Exercise 4 Draw a very simple class diagram showing the relationship between children and their biological parents. Don’t worry about attributes etc. Can you represent the same relationship using only one class.

16 IS0514Slide 16 Exercise 4 – One solution

17 IS0514Slide 17 Recursive Association - is allowed, and can be useful ! an employee, as a manager, may manage other employees; each employee may be managed by another employee employee  manages 0..* 0..1

18 IS0514Slide 18 Class v. Object Diagram Staff staffName staffID staffstartdate staffdept AkhtarAli:Staff staffName=Akhtar Ali staffID=313 staffstartdate=140800 staffdept=SDE full symbol for an object is a box with 3 compartments class name attributes operations an instance symbol shows both instance and class name underlined with a colon to separate in an instance symbol, both attribute names and values are given

19 IS0514Slide 19 Exercise 5 Given the class diagram Draw the object diagram given the following instances –Ford Fiesta £4999 –Subaru Impreza WRD £22000 with a flash stereo –Hyundai Accent £7995 with child seats

20 IS0514Slide 20 Exercise 5 – One Answer make=Ford model=Fiesta price=£4999 ThisFordFiesta:Car make=Subaru model=Impreza price=£22000 thisSubaruImpreza:Car make=Hyundai model=Accent price=£7999 thisHydundaiAccent:Car name=stereo :Accessory car accessory name=Child Seats childseats:Accessorycar accessory

21 IS0514Slide 21 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

22 IS0514Slide 22 Summary Visibility Association classes Constraints Recursive relationships Object diagrams Next week –Behavioural Model –Class Responsibility Collaboration Cards


Download ppt "IS0514Slide 1 IS0517 Lecture Week 8 Class Diagrams III."

Similar presentations


Ads by Google