0% found this document useful (0 votes)
19 views

lecture-08-class-diagram-II

Uploaded by

ffff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

lecture-08-class-diagram-II

Uploaded by

ffff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 33

ITSE 2F12

Software Engineering
Lecture 8
Software Design: Class Diagrams

Uml.org
Sparxsystems.com.au/resources/uml2_tutorial
Martin Fowler, UML Distilled
Outline
 Class Relationships and UML Notations
 Association
 Generalization
 Realization
 Dependency
 Class Diagram
 Object Diagram
 Summary

2
Association - Multiplicity
 A Student can take many Courses and many
Students can be enrolled in one Course.

Student Course
* takes *

Alice: Student 254: Course

Jill: Student 253: Course

3
Notes
 One class can be relate to another in a
 One-to-one
 One-to-many
 One-to-one or more
 One-to-zero or one
 One-to-a bounded interval (one-to-two
through twenty)
 One-to-exactly n
 One-to-a set of choices (one-to-five or
eight)

4
Notes
 Multiplicity can be expressed as,
 Exactly one - 1
 Zero or one - 0..1
 Many - 0..* or *
 One or more - 1..*
 Exact Number - e.g. 3..4 or 6
 Or a complex relationship – e.g. 0..1, 3..4,
6..* would mean any number of objects
other than 2 or 5

5
Association - Self
 An association that connects a class to itself is
called a self association.

6
Association - Self
 A Company has Employees.
 A single manager is responsible for up to 10 workers.

1
Employee
manager
Responsible worker
0..10
for

7
Association - Multiplicity
 A football team has 11 players. One of them is the
captain.
 A player can play only for one Team.
 The captain leads the team members.

Captain
Team
Memb 1
er Player 0..1
Team
10

11 member of 1
Captain
1

Lead
8
s
Association types Car

 aggregation: "is part of" 1 aggregatio


n
1
 clear white diamond Engine

 composition: "is entirely Book

made of" composition

 stronger version of 1
aggregation * Page
 the parts live and die with the
whole
 black diamond
Class Relationships
 Association
 Generalization
 Realization
 Dependency

10
Generalization
(Inheritance)
 Child class is a special case of the parent
class
SuperClass

SubClass1 SubClass2

 Omit generalization relationships, such as


drawing the Object class as a parent in Java
11
Generalization (Inheritance)
e.g.

Circle

GraphicCircle

12
Inheritance -
Implementation

public class Circle {

public class GraphicCircle extends Circle {

13
Abstract Class
• If the class is defined as Abstract no
objects of the class can be instantiated.
• If at least one method in a class is defined
as abstract then the class is abstract.

Shape

Circle Rectangle
14
Abstract Methods (Operations)

Shape
draw()

Circle Rectangle

draw() draw()

15
Abstract class and method
Implementation

public abstract class Shape {


public abstract draw(); //declare without implementation
………
}

public class Circle extends Shape{


public draw(){
…….
}
…..
}

16
Class Relationships
 Association
 Generalization
 Realization
 Dependency

17
Realization- Interface
 Interface is a set of operation the class carries
out
 Interface doesn’t have
attributes, only method
signatures
 Classes can implement
the methods

Signatures serve as a contract
 Relationship Represented
by a dashed, white arrow

18
Realization -
Implementation
public interface Shape{
abstract double getArea();

public class RectangularShape implements Shape{


public double getArea(){
return width * height;
}
}

19
Class Relationships
 Association
 Generalization
 Realization
 Dependency

20
Dependency
 Change in specification of one class can
change the other class.
 This can happen when one class is using
another class.

E.g If you change a point from a 2D point to a 3D
point, you also need to change the move method to
draw a 3D movement
Circle
Point
Move(p:Point)

21
Dependency cont
 Dependency relationship can be used to
show relationships between classes and
objects.
f>>
c eO circleA:Circle
an
i n st
<<
Circle
<<
i
ns
ta
nc
eO circleB:Circle
f>
>

22
Class Diagrams
 The UML class diagram consists
of several Classes, connected
with Relationships.

Must include Entity classes

Sometimes controller is included

Usually Boundary classes are left
out

Including them makes the diagram
complex
23
Example: video store
 qq

24
Class Diagram - Example
 Draw a class diagram for a information modeling
system for a school.
 School has one or more Departments.
 Department offers one or more Subjects.
 A particular subject will be offered by only one
department.
 Department has instructors and instructors can work
for one or more departments.
 Student can enrol in upto 5 subjects in a School.
 Instructors can teach upto 3 subjects.
 The same subject can be taught by different
instructors.
 Students can be enrolled in more than one school.

25
Class Diagram - Example
 School has one or more Departments.

School Department
1 has 1..*

 Department offers one or more Subjects.


 A particular subject will be offered by only on

department.

Department Subject
1 offers 1..*
26
Class Diagram - Example
 Department has Instructors and
instructors can work for one or more
departments.

Instructor Department
1..* assigned to 1..*

 Student can enrol in upto 5 Subjects.

Student Subject
* takes 0..5
27
Class Diagram - Example
 Instructors can teach up to 3 subjects.
 The same subject can be taught by
different instructors.

1..*
Instructor Subjects
teaches 1..
3

28
Class Diagram - Example
 Students can be enrolled in more than
one school.

*
Student School
member 1..
*

29
Class Diagram Example
has

School Department
1 1..* 1..*

1…* 1
offeres
assignedTo
member

* 1..* 1..*

attends teaches Instructor


Student Subject
* 1..5 1..3 1..*

30
Object Diagram
 Object Diagram shows the
relationship between objects.

 Unlike classes objects have a state.

31
Object Diagram - Example
c1: Company
c1: Company
name=“UniMelb”

d1: Department d2: Department

name=“Sales” name=”CSSE”

manager employee

p1: Persont p2: Person

name=“Rao” name=“Raj”
32
Summary
 We have discussed the following concepts
and UML notations related:
 Association
 Generalization
 Realization
 Dependency
 How to create a Class Diagram that
contains all the above relationships
 Object Diagram for Uni.Dept.system.

33

You might also like