Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Systems Design – 3 Class Diagrams (static structure) Klaas Sikkel Software SystemsDesign - 31.

Similar presentations


Presentation on theme: "Software Systems Design – 3 Class Diagrams (static structure) Klaas Sikkel Software SystemsDesign - 31."— Presentation transcript:

1 Software Systems Design – 3 Class Diagrams (static structure) Klaas Sikkel Software SystemsDesign - 31

2 Today’s topic Software SystemsDesign - 32

3 Contents 1.What is object-orientation? 2.(Static) class diagrams 3.What does a class diagram represent? 4.Extensions to class diagrams 4.1. Association classes 4.2. Generalization Software SystemsDesign - 33

4 1. What is object-orientation? Software SystemsDesign - 34

5 What is object-orientation? Philosophical perspective: A way to understand how concepts are structured in the world – Generalization / Specialization A tiger is a cat – Subspecies include Bengal, Sumatran and Siberian tiger A cat is a mammal A mammal is a vertebrate All cats have something in common that they do not share with other mammals Software SystemsDesign - 35

6 What is object-orientation? Philosophical perspective: A way to understand how concepts are structured in the world – The concept “cat” describes a set of individual animals that share certain properties (Class vs. Object) Software SystemsDesign - 36

7 What is object-orientation? Programming / Software Engineering perspective: A programming paradigm in which functionalities are assigned to particular kinds of data – Supports polymorhism – Supports information hiding Software SystemsDesign - 37

8 Example of a class Software SystemsDesign - 38

9 Pre-object-oriented programming Oversimplification: In the early days of programming, the focus was mostly on programming logic. What happened to the data depended on the logic. In object-oriented programming the data are more central and the programming logic depends on the (type of) data. Software SystemsDesign - 39

10 Polymorphism Software SystemsDesign - 310

11 Information hiding One cannot directly access an object’s data; one can only access the data through a method Consequence: Makes software easier to scale up Makes software easier to maintain Software SystemsDesign - 311

12 2. (Static) class diagrams Software SystemsDesign - 312

13 2. (Static) Class diagrams A class diagram is used to describe – What the objects are that should be stored in the system – How these objects are structured – How these objects relate to each other –(Not: what functionality these objects offer) Software SystemsDesign - 313

14 Simple example Software SystemsDesign - 314 CD for (part of) a company’s administration

15 Class vs. Object Class Describes what we want to know about an employee Object Stores data of one particular employee Software SystemsDesign - 315

16 Elements of a CD (1): Class Notation:Example: N.B.: class name is a singular noun Software SystemsDesign - 316

17 Elements of a CD (2): Attributes A class has zero or more attributes For every attribute a standard data type can be specified – Can be omitted if the data type is obvious and/or not interesting in a given context Standard data types include: - Integer- Date - Real- Time - Boolean- Money - String Software SystemsDesign - 317

18 Elements of a CD (3): Association (Notation will be elaborated on next slides) multiplicities (Elements between brackets[ ] are optional) name Direction of the association role of Class 2 in the association Software SystemsDesign - 318

19 Examples An employee lives at an address At any address zero or more employees are living Software SystemsDesign - 319

20 Examples An employee lives at an address At any address one or more employees are living Software SystemsDesign - 320

21 Examples Multiple associations between two classes Software SystemsDesign - 321

22 Examples Software SystemsDesign - 322

23 Multiplicities Software SystemsDesign - 323

24 Roles in an association Consider the following CD Software SystemsDesign - 324

25 Roles in an association We can use a role name, rather than association name, if a class has a specific role in the association Software SystemsDesign - 325

26 Direction of an association An association has a direction ( by default: – from left to right – from top to bottom We can explicitly indicate direction with, ^, v Software SystemsDesign - 326

27 Direction of an association Software SystemsDesign - 327

28 Conventions for associations In principle, every association has a name. If a role is indicated, the association name can be discarded By default an association is read from left to right or top to bottom A direction can be stated explicitly by ‘ ’, ‘^’, ‘v’ All multiplicities are explicitly given Software Systems28Design - 3

29 3. What does a class diagram represent? Software SystemsDesign - 329

30 CD as a model of the physical world [Lecture 1]: A model is a simplified representation of part of the world, from a particular view For Class Diagrams specifically: View: Focus on data (not functions/behaviour) Part of the world: The subject we’re modelling Simplified: Only those data that should be represented in the system Software SystemsDesign - 330

31 CD as a model of the physical world John Smith Representation of John Smith in the system Software SystemsDesign - 331

32 Is the model an adequate representation? Possibly reality is not correctly represented in the system – John Smith moved to a new address but no-one told the system This does not invalidate the class diagram There are models in which reality cannot be represented – “Every employee works at one particular department”: What to do if someone has two part-time jobs at different departments? Software SystemsDesign - 332

33 Which is the right model of an address? Design - 333Software Systems

34 Class and identity Two different objects can have the same values for all attributes Internally they are distinguished by a different key Such keys are not represented in the class diagram – unless these keys have spilled over into reality and now exist outside the system (student number, social security number, etc., … Software SystemsDesign - 334

35 Snapshot vs. historic information Do we model the world as it exists now, or do we include data from the past? This is a conscious choice. Usually snapshot, sometimes historic information (in exercises it is always clear what was meant) Example of a snapshot: Employee has one adres, one manager Example of historic information: Incidents in the police information system. They will remain to be recorded after the incident has been dealt with. Software SystemsDesign - 335

36 Class or attribute? Rule of the thumb: An entity is an attribute if it is only used as a particular data item of a class An entity is a class – If it can have multiple values – If it has attributes by itself – If it has associations with other classes Software SystemsDesign - 336

37 Pitfalls Synonyms (different words for the same concept) Homonyms (one word for different concepts) Software SystemsDesign - 337

38 Different levels of abstraction Special case of homonym We use one word for a concept on different levels of abstraction – The book ‘Bonita Avenue’ – One copy of the book ‘Bonita Avenue’ – The Alfa Romeo 159 (type of car) has certain properties – The Alfa Romeo 159 (particular car) which is parked in front of this building Software SystemsDesign - 338

39 Different levels of abstraction This distinction is important! And it remains to be difficult! Software SystemsDesign - 339

40 Yet another example Member wants to reserve a book. The system says that it has been borrowed by someone and will Be returned in two weeks. However, there are two copies still in the library. Reservations and loans in a library Inappropriate model: Impossible to indicate multiple copies of the Same book Software SystemsDesign - 340

41 Compare ‘Car’ and ‘Car type’ Yet another example Reservations and loans in a library Software SystemsDesign - 341

42 4.1 Association classes Software SystemsDesign - 342

43 Problem How can we assign a grade to the test? Software SystemsDesign - 343

44 Association class: Example Software SystemsDesign - 344

45 Identity of an association class The identity of an object of an association class is defined as combination of the identity of the associated objects. That means: – One ‘participation’ is identified by the combination of one student and one exam Software SystemsDesign - 345

46 Elements of a CD (4): Association class Software SystemsDesign - 346

47 Associatieclass vs. class Are these models equivalent? (b) (a) Software SystemsDesign - 347

48 Identity of an association class Identity is combination of the identities of the associated classes That implies, for (a): – A contract is defined by a unique combination of employee and company – Differently stated: For a combination of one person and one company there can only be a single contract But in case (b): – A person and a company can have multiple contracts Software SystemsDesign - 348

49 For a student who participates in an exam there is exactly one grade Software SystemsDesign - 349

50 A last example Marriage: snapshot viewMarriage: historical view Software SystemsDesign - 350

51 Special case: Liz Taylor & Richard Burton Married: 15 March 1964 — Divorced 26 June 1974 Married: 10 October 1975 — Divorced: 29 July 1976 Design - 3

52 Liz Taylor & Richard Burton Inadequate model Adequate model Software SystemsDesign - 352

53 4.2 Generalization Software SystemsDesign - 353

54 Generalization example Software SystemsDesign - 354

55 Elements of a CD (5): generalization Elements: discriminator static/dynamic dc / d / c / _ Class 1 is the superclass of Classes 2 and 3 Class 3 is a subclass of Class 1 Design - 3

56 Elements of generalizations (1) Discriminator – discriminator is one of the attributes of the super class >/ > – Static: an object cannot chance subclass Example: a bicycle never becomes a car – Dynamic: an object could belong to different subclasses at different moments in time Example: student graduates and becomes employee Software SystemsDesign - 356

57 Elements of generalizations (2) Disjoint generalization: an object can belong to at most one subclass Not disjoint: anobject can belong to different subclasses at the same time (student assistant is both student and employee) Covering generalization: every object of the superclass belongs to (at least) one subclass Not covering: there can be objects that don’t belong to any subclass (external staff; is in the database but not an employee) Software SystemsDesign - 357

58 Disjoint and covering dc d c ? Software SystemsDesign - 358

59 Use of generalization We use a generalization if … …subclasses can be distinguised that have different attributes … subclasses can be distinguished that have different associations Software SystemsDesign - 359

60 Use of Generalization Different attributes for ‘Student’ and ‘Teacher’ Software SystemsDesign - 360

61 Use of Generalization Different assocations for ‘Student’ and ‘Teacher’ Software SystemsDesign - 361

62 Use of Generalization Contains the same information as the previous slide (Subclass without attributes can be deleted) Software SystemsDesign - 362

63 Generalization: more examples Design - 3

64 Generalization: more examples Design - 3

65 Self-study and Laboratory exercise Please note: The self-study prepares for the lab exercise There is good reason for that: Wednesday’s lab exercise is quite challenging So do your homework and be prepared! Software SystemsDesign - 365


Download ppt "Software Systems Design – 3 Class Diagrams (static structure) Klaas Sikkel Software SystemsDesign - 31."

Similar presentations


Ads by Google