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

lecture-06a-class-diagram - SW

The document discusses software design principles, focusing on object-oriented design and the use of UML (Unified Modeling Language) for class diagrams. It covers the identification of classes, their responsibilities, and interactions through CRC (Class-Responsibility-Collaborators) cards, as well as the various types of classes and their relationships. Additionally, it provides examples of class diagrams and the importance of multiplicity in associations between classes.

Uploaded by

Natty 123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

lecture-06a-class-diagram - SW

The document discusses software design principles, focusing on object-oriented design and the use of UML (Unified Modeling Language) for class diagrams. It covers the identification of classes, their responsibilities, and interactions through CRC (Class-Responsibility-Collaborators) cards, as well as the various types of classes and their relationships. Additionally, it provides examples of class diagrams and the importance of multiplicity in associations between classes.

Uploaded by

Natty 123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Software Engineering

Lecture 6
Software Design

Reading: Ian Summervillie – software engineering chapter 5


Bruggie – Object-oriented software engineering
Uml.org
Sparxsystems.com.au/resources/uml2_tutorial
Martin Fowler, UML Distilled
Software Design
• Design: specifying the structure of how a software system
will be written and function, without actually writing the
complete implementation
– The most common design is Object-Oriented
– Therefore structure is usually represented by Classes and
collaboration by Class  Class interactions

• Design: A transition from "what" the system must do, to


"how" the system will do it
– What classes will we need to implement a system that meets our
requirements?
– What fields and methods will each class have?
– How will the classes interact with each other?
2
Design is all about classes
• Identify classes and interactions from use cases:
– Nouns are potential classes, objects, and fields
• E.g student, grade, order, registration form, …
– Verbs are potential methods or responsibilities of a class
• E.g register, encode grade, submit order
– Relationships between nouns are potential interactions
(containment, generalization, dependence, etc.)
• Student registers for Course, customer orders pizza, …
• To Design
– Which nouns should be classes?
– Which ones are fields?
– What verbs should be methods?
– What are potential interactions between your classes?
3
CRC – to identify classes
• Walk through functional (use-cases) and non functional req.
and create CRC for noun.
• CRC (class-responsibility-collaborators) cards
– on top of the card, write down the name of the class
– below the name, list the following:
• responsibilities: problems to be solved; short verb phrases
• collaborators: other classes that are sent messages by this class

4
Types of Classes
– Entity class a.k.a domain class
• A class that exists in the problem domain. E.g student, course,…
(usually remembered)
• These are the most important classes.

– Boundary class or view class


• a class that exists on a system’s automation boundary, such as an
input window form or Web page

– Control class
• a class that mediates between boundary classes and entity classes,
acting as a switchboard between the view layer and domain layer
• Consider this to be an eventHandler – takes an event from boundary
class and calls the Entity class

5
CRC – How To?
– Create a CRC for the entity object will receive the first message
from the controller (primary object)
• For example, a Customer object for new sale.
• Questions to ask:
– What are its responsibilities
– What information does the class need to do its responsibilities
– Create CRC for other classes that must collaborate with the
primary object class to complete the use case.
• Questions to ask:
– What are its responsibilities
– What information does the class need to do its responsibilities

6
Example – CRC Cards Results
Several Use Cases

7
Case Study
• Use Case Diagram for Student Assessment Management
System Grade system

Record
grades
Student
View grades

Teacher Distribute
Report cards

Create report
cards Printing administrator

8
Noun analysis From
Requirements
• A University record system should keep information about its
students and academic staff.

• Records for all university members are to include their id


number, surname, given name, email, address, date of
birth, and telephone number.
– Students and academic staff each have their own unique ID
number: studN (students), acadN (academic employee),
where N is an integer (N>0).

• In addition to the attributes mentioned above:


– Students will also have a list of subjects they are enrolled in. A
student cannot be enrolled in any more than 10 subjects.
– Academic employees will have a salary, and a list of subjects
they teach. An academic can teach no more than 3 subjects 9
Unified Modelling Language
• Union of Many Languages
– Use case diagrams – we already discussed these!
– Class diagrams
– Object diagrams
– Sequence diagrams
– Collaboration diagrams
– Statechart diagrams
– Activity diagrams
– Component diagrams – we already discussed these!
– Deployment diagrams – we already discussed these!

• Each different architecture of the system


– Static architecture, dynamic architecture, physical architecture
10
What is a UML class diagram?
• A UML class diagram is a picture of
– the classes in an OO system
– their fields and methods
– connections between the classes that interact or inherit from each
other

• Not represented in a UML class diagram:


– details of how the classes interact with each other
– algorithmic details; how a particular behavior is implemented
Class diagram
• Shows classes and relationships among them.
– A static view (static architecture) of the system, displaying what
interacts but not what happens when they do interact.
11
Modeling a class in UML
• When modeling a class in UML, we have a lot of flexibility.
• The same class can be modeled in four different ways:
– With no attributes or operations shown
– With only the attributes shown
– With only the operations shown
– With both the attributes and operations shown
• The name of the class is always the first component of the
class box;
• Class
– The rectangle is the icon for the class
– Convention – the name of the class is a word with an initial
uppercase letter.
– It appears near the top of the rectangle.
– If your class name has more than one word name, capitalize the
first letter of the every word.
12
Classes

ClassName

Circle

13
Classes (with attributes and operations)

ClassName
ClassName
attr1:type1
attr1:type1 attr2:type2=“def”
attr2:type2=“def” operation1()
operation2(args)
operation3() : ret type

Circle
Circle centreX:Int
centreX:Int centreY:Int=0
centreY:Int=0 draw()
move(Int X, Int Y)
14
Classes (with attributes and operations)
• Attribute
– is a property of a class (E.g centreX, centreY,…).
– A class may have zero or more attributes.
– A one-word attribute name is written in lowercase letter.
– If the name consists of more than one word each word other than
the first word begins with an uppercase letter.
– The list of attribute names begins below a line separating them
from the class name.

• Operations
– An operation is something that a class Circle
can do, or that you (or another class) centreX:Int
can do to a class.
– Naming – similar to attribute centreY:Int=0
– The list of operations begins below a draw(): void
line separating operations from the move(Int X, Int Y): void
attributes.
15
Class Visibility
• Visibility
– specifies the extent to which other classes can use a given class's
attributes or operations.
– applies to attributes or operations
– Three levels of visibility are possible
• public level - usability extends to other classes +
• protected level - usability is open only to classes that inherit from
original class #
• private level - only the original class
can use the attribute or operation - Circle
- centreX:Int
- centreY:Int=0
+ draw()
# move(Int X, Int Y)16
Class Stereotypes in UML
• stereotype a way
of categorizing a
model element by
its characteristics,
indicated by
<< >>

17
Class - Implementation
public class Circle {

private int centreX, centreY=0; // centre of the circle

//Methods to return circumference and area


protected double move() {
// Implementation here
}
public void draw() {
// Implementation here
}
}

18
Class Multiplicity
• A multiplicity in a class specifies the number of
instances (objects) of that class that can exist
simultaneously.
1
Library

• Only one Library object is allowed in the system


(referred to as a singleton object).

19
Objects: Instances of Classes

d1: Department : Department

(a) (b)

d1: Department : Department

name = “Sales” name = “Sales”


deptNo = 1 deptNo = 1

(c) (d)
20
Class Relationships
• Classes can related to each other through different
relationships:
– Association (delegation)
– Generalization (inheritance)
– Realization (interfaces)
– Dependency

21
1. Association
• Association describes a link, a link being a connection among
objects between classes.
• Association is shown by a solid line between classes.
Eg. A Person works for a Company.

Role

employee employer
Person Company
works for

Association Name

22
Association - Properties
• Name
– Name of the association
• Role
– The specific role of the association
• Multiplicity
– Indicates the number of objects that are connected
• Type
– Plain association, aggregation, composition
• Direction
– Direction can also be shown for a association

23
Association - Multiplicity
• Multiplicity on association specify properties of the
number of links that can exist between instances
(objects) of the associated classes.
– That is, it indicates how many objects of one class relate to
one object of another class. It is indicated by a single
number or a range of numbers.
• We can add multiplicity on either end of class
relationship by simply indicating it next to the class
where the relationship enters.

Association name
Class1 Class2
multiplicity multiplicity
24
Association - Multiplicity
• A Student can take up to five Courses.
• Student has to be enrolled in at least one course.
• Up to 300 students can enroll in a course.
• A class should have at least 10 students.

Student Course
10..300 takes 1..5

25
Association
Association - Multiplicity
– Multiplicity
• A teacher teaches 1 to 3 courses (subjects)
• Each course is taught by only one teacher.
• A student can take between 1 to 5 courses.
• A course can have 10 to 300 students.

1 teaches 1..3
Teacher Course
1..5

takes
Student
10..300

26
• 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
Self Association: An association that connects a class to itself
is called a self association.

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

1
Employee
manager
Responsible worker
0..10
for

28
Association types Collage

 aggregation: "is part of"/“Has a” 1 aggregation

1
 Unidirectional/not vice versa Teacher
 clear white diamond
 composition: "is entirely made Book

of“ / “Contained” composition

 stronger version of aggregation 1


 the parts live and die with the * Page
whole
 black diamond
2. Generalization
(Inheritance)
 Child class is a special case of the parent class
SuperClass

SubClass1 SubClass2

30
Inheritance - Implementation

public class Circle {

public class GraphicCircle extends Circle {

What is Abstract Class??

31
3. Realization- Interface
• The relationship between a class and an interface is
called realization.
 Interface class doesn’t have
attributes, only method
signatures
 Classes can implement
the methods
 Relationship Represented
by a dashed, white arrow

32
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)

33
Dependency cont
 Dependency relationship can be used to show
relationships between classes and objects.

f >>
nc eO circleA:Circle
ta
ins
<<

Circle

<<
i
ns
tan
ce
Of circleB:Circle
>>

34
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

35
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.

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

School Department
1 has 1..*

Department offers one or more Subjec


 A particular subject will be offered by only o


departme

Department Subject
1 offers 1..*
37
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
38
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

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

*
Student School
member 1..*

40
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..*

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

 Unlike classes objects have a state.

42
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”
43
Tasks to do this week
 Revision on oo concepts.
 Identify your classes and objects in your
project.

44

You might also like