Lecture 5 - Object Design-3
Lecture 5 - Object Design-3
SWE30003
Software Architecture and Design
Lecture 5
Object Design (Part I) –
Responsibility-Driven Design
Logistical matters
Weekly submissions – A & Q
Week 2: 361 & 346 out of 434;
Week 3: 380 & 366 out of 434;
Week 4:
Week 5:
Week 6:
Note that this is a hurdle requirement
No late submission
Principal References
Rebecca Wirfs-Brock, Brian Wilkerson and Lauren
Wiener, Designing Object-Oriented Software, Prentice
Hall, 1990, Chapters 3 to 5.
Bernd Bruegge and Allen H. Dutoit, Object-oriented
Software Engineering, Prentice Hall, 2001, Chapter 5.
Shari L. Pfleeger, Software Engineering: Theory and
Practice (2nd Edition), Prentice Hall, 2001, Chapters 5
and 6.
Ian Sommerville, Software Engineering (9th Edition),
Addison Wesley, 2013, Chapter 7.
4
Object-Oriented Design
OOD != OOP
Roadmap
Preliminaries
Objects and Classes
What is Object-Oriented Design?
Finding Classes
Class Selection Rationale
CRC Cards
Identifying Responsibilities
Finding Collaborations
6
Decomposition
Decomposition is a process that helps to
manage the complexity of the system
Starting with a high-level view of the system.
Creating the low-level details of the features
of the system in turn.
Stop when we are satisfied with the level of
detail.
Also known as Divide-and-Conquer.
Decomposition (cont.)
Top level
Adapted from Figure 5.3, Pfleeger 2001
“Architecture”
First level
Second level
Cohesion:
measure the intra-dependency of a system part
Roadmap
Preliminaries
Objects and Classes
What is Object-Oriented Design?
Finding Classes
Class Selection Rationale
CRC Cards
Identifying Responsibilities
Finding Collaborations
10
10
What is an Object?
Analysis and modeling view:
an abstract model of a real world entity that has an independent identity.
E.g., Computer, Person, Car
Design and implementation view
a software component that contains a collection of data and related
procedures.
An object
represents something in real world that has an independent identity.
is something that you can interact with:
receive and response to messages.
has behaviour which may depend on its internal state which may change
by responding to messages.
Object vs Class
11
11
What is an Object?
knows performs
information Processing computations
Object
Interaction Composition
12
In fact…
contains performs
information computations
Processing
Element
13
What is a Class?
A class is a description of a group of objects with
common data attributes
common operations
common relationships to objects; and
common semantics (i.e. “meaning”)
Classes in UML
Don’t worry
about visibility
too early!
15
Objects in UML
Objects are shown as rectangles with their name and type
underlined in one compartment, and attribute values, optionally, in a
second compartment.
Roadmap
Preliminaries
Objects and Classes
What is Object-Oriented Design?
Finding Classes
Class Selection Rationale
CRC Cards
Identifying Responsibilities
Finding Collaborations
17
17
Object-oriented Design
18
19
19
Roadmap
Preliminaries
Objects and Classes
What is Object-Oriented Design?
Finding Classes
Class Selection Rationale
CRC Cards
Identifying Responsibilities
Finding Collaborations
20
20
Functional Decomposition:
21
21
Object-Oriented Decomposition:
However
How to find the objects?
22
22
Responsibility-driven design is an
(analysis and) design technique that
works well in combination with various
methods and notations.
23
23
24
25
25
26
26
Finding Classes
27
27
28
28
29
29
The text creation tool changes the shape of the cursor to that of an I-beam. The
position of the first character of text is determined by where the user clicks the
mouse button. The creation tool is no longer active when the user clicks the mouse
button outside the text element. The control points for a text element are the four
corners of the region within which the text is formatted. Dragging the control points
changes this region. The other creation tools allow the creation of lines, rectangles
and ellipses. They change the shape of the cursor to that of a crosshair. The
appropriate element starts to be created when the mouse button is pressed, and is
completed when the mouse button is released. These two events create the start
point and the stop point.
The line creation tool creates a line from the start point to the stop point. These
are the control points of a line. Dragging a control point changes the end point.
The rectangle creation tool creates a rectangle such that these points are
diagonally opposite corners. These points and the other corners are the control
points. Dragging a control point changes the associated corner.
The ellipse creation tool creates an ellipse fitting within the rectangle defined by
the two points described above. The major radius is one half the width of the
rectangle, and the minor radius is one half the height of the rectangle. The control
points are at the corners of the bounding rectangle. Dragging control points changes
the associated corner.
30
30
Roadmap
Preliminaries
Objects and Classes
What is Object-Oriented Design?
Finding Classes
Class Selection Rationale
CRC Cards
Identifying Responsibilities
Finding Collaborations
31
31
32
32
33
33
corner
associated corner, diagonally opposite corner
no new behaviour
34
34
Model categories:
Tool, Creation Tool
Model interfaces to the system: — no good candidates here ...
user — don’t need to model user explicitly
cursor — cursor motion handled by operating system
35
35
36
36
Candidate Classes
Preliminary analysis yields the following candidates:
37
xfig
38
38
39
39
Roadmap
Preliminaries
Objects and Classes
What is Object-Oriented Design?
Finding Classes
Class Selection Rationale
CRC Cards
Identifying Responsibilities
Finding Collaborations
40
40
Record the candidate Class Name and superclass (not yet known)
Record each Responsibility and the Collaborating classes
compact, easy to manipulate, easy to modify or discard!
easy to arrange, reorganize
easy to retrieve discarded classes
41
41
42
42
Roadmap
Preliminaries
Objects and Classes
What is Object-Oriented Design?
Finding Classes
Class Selection Rationale
CRC Cards
Identifying Responsibilities
Finding Collaborations
43
43
Responsibilities
What are responsibilities?
the knowledge an object maintains and provides,
the actions it can perform.
44
Identifying Responsibilities
Study the requirements specification:
highlight verbs and determine which represent
responsibilities
perform a walk-though of the system
explore as many scenarios as possible
identify actions resulting from input to the system
45
45
Pelrine’s Laws:
“Don't do anything you can push off to someone else.”
“Don't let anyone else play with you.”
46
46
Assigning Responsibilities
Evenly distribute system intelligence
avoid procedural centralization of responsibilities
keep responsibilities close to objects rather than their clients
Note: this is not always possible (or even desirable)!
47
47
48
49
49
50
50
Example Relationships
51
51
Roadmap
Preliminaries
Objects and Classes
What is Object-Oriented Design?
Finding Classes
Class Selection Rationale
CRC Cards
Identifying Responsibilities
Finding Collaborations
52
52
Collaborations
53
53
Finding Collaborations
54
54
Listing Collaborations
Drawing
55
55
Summary
56
56
57
57
58
58
59
59