Presentation is loading. Please wait.

Presentation is loading. Please wait.

IMSE 11 - UML Class Diagrams

Similar presentations


Presentation on theme: "IMSE 11 - UML Class Diagrams"— Presentation transcript:

1 IMSE 11 - UML Class Diagrams
a modeling language is the graphical notation used in developing a system UML is known as the Unified Modeling Language because it unifies the earlier graphical notations of: Booch Jacobson and Rambaugh (the 3 amigos) who collaborated to produce UML other important O-O precursors: Coad and Yourdon (OOA, OOD) Wilfs-Brock (responsibility-driven design) Cunningham and Beck (class-responsibility-collaboration cards) UML is very young (1998) and is now the industry-wide standard modeling language for O-O systems

2 Familiar and Unfamiliar Concepts in UML
UML caters for many of the general OO concepts we are already familiar with, e.g. classes with attributes and operations or methods relationships between classes (inheritance (known as generalisation in UML) aggregation, association) cardinality of relationships, known as multiplicity in UML abstract classes some concepts we haven’t met in earlier lectures are provided by UML, e.g. multiple classification, dynamic classification, composition, derived attributes, qualified association, parameterised classes

3 UML Diagrams UML uses diagrams and symbols of many types, e.g.
class diagrams interaction diagrams: sequence diagrams collaboration diagrams use case diagrams package diagrams state diagrams activity diagrams deployment diagrams many of the diagrams are developed in and belong to the analysis stage of software development for the high level design of a system we will focus on class diagrams

4 Class Diagrams describe the types of objects in the system
show the attributes and operations show the static relationships between the objects main types of relationships: - generalisation - “type of” - association e.g. project leader and company car - aggregation and composition - “part of” also show multiplicity, navigability, derived attributes, visibility (public, private, protected), multiple classification, discriminators, dynamic classification etc, etc ...

5 Generalisation ... ... UML’s term for inheritance is generalisation
Student reg no. name address change address a clear triangular arrowhead symbolises generalisation superclass subclass BABC Student BUS279 gp ... HND Student COH208 gp ... HND students are a type of student

6 Association and Roles an association has 2 roles, e.g:
- the role from project leader to company car - the role from company car to project leader a role may be labeled with a name: - a project leader “has the use of” a company car - a company car “is allocated to” a project leader the name of the role can be the same as the target class Project Leader name ... Company Car reg. no. ... has the use of is allocated to

7 Multiplicity multiplicity is UML’s term for cardinality
multiplicity is shown on class diagrams it states how many objects can participate in a relationship 1 precisely one n n is any number * the range zero to infinity 1 .. * the range one to infinity zero or one n1 .. n2 the range n1 to n2 (one number to another) e.gs. car and engine book and pages 1 *

8 Aggregation the “part of” relationship e.g. car and engine
symbolised by a clear diamond some analysts would also include a company and its employees the multiplicity is shown, a car and engine have a 1 to 1 relationship of association engine car 1 aggregation

9 Composition stronger version of aggregation
the parts live and die with the whole symbolised by a filled-in diamond 2 ways of representing composition: pages book book pages * composition 1 * multiplicity = * i.e. any no. from 0 upwards

10 Navigability does the project leader class have an attribute for storing a company car registration number? or does the company car class have an attribute for holding a project leader’s name? or both? to describe this we say that the association between project leader and company car has a navigability navigabilities are shown by an arrow, which may be uni-directional or bi-directional

11 Navigabilities the direction of the association arrow reveals the class that knows (or is responsible for) which object it will be associated with Project Leader name car reg. no.. ... Project Leader name ... Project Leader name car reg. no. ... Company Car reg. no. .. Company Car reg. no. proj ldr’s name ... Company Car reg. no. proj ldr’s name ..

12 Derived Attributes date of birth is an attribute of person
age is a derived attribute as it is not stored, but can be derived from date of birth derived attributes are symbolised by a forward slash Person date of birth / age derived attribute

13 Visibility the attributes and operations of a class may have public, private or protected visibility public - can be used by any other class private - can be used only by objects of this class protected - can be used by this class and its subclasses UML notation for each: + public e.g. + name - private e.g. - salary # protected e.g. # display supervisor subtle differences exist at implementation stage, depending on the programming language used

14 Multiple Classification
classification - the relationship between an object and its type single classification - an object belongs to a single type which may inherit from supertypes multiple classification - an object may be described by several types not necessarily connected by inheritance e.g. a person may also be described as - a man or a woman - and a patient - and a doctor or a nurse note that multiple classification is completely different to multiple inheritance, e.g. a hovercraft each hovercraft is an instance of the single type hovercraft, even though it has more than one supertype

15 Example of Multiple Classification
Female Male Doctor Nurse Person Patient

16 Discriminators male and female are subtypes of person
each person cannot be both male and female each person cannot be both a doctor and a nurse we show this on a class diagram by joining the generalisation lines into one triangular arrowhead, and labelling the line with a discriminator so several subtypes share a discriminator and if a discriminator is labeled {complete} then an instance of the supertype (e.g. person) must be an instance of one of the subtypes (e.g. female) note that sex is a complete discriminator but job is not - as every person is either male or female, but not every person is a doctor or nurse

17 Example of Multiple Classification
discriminator sex {complete} Female Male Person Patient Doctor Nurse job <<dynamic>> Legal combinations: female, patient, doctor male, nurse male, patient Illegal combinations: patient, doctor (must include male or female as sex is a complete discriminator) female, doctor, nurse (contains 2 types from the discriminator job)

18 Dynamic Classification
on the class diagram showing the example of multiple classification the discriminator “job” is marked as <<dynamic>> this shows that a person’s job in the system will be able to change (nurses may become doctors and vice versa) so objects are allowed to change type within the subtype structure dynamic classification allows this, static classification does not useful for bank accounts - when a bank account is overdrawn it changes behaviour - operations such as withdraw and close are overridden


Download ppt "IMSE 11 - UML Class Diagrams"

Similar presentations


Ads by Google