Beruflich Dokumente
Kultur Dokumente
Michael Eichberg
Software Technology Group
Department of Computer Science
Technische Universitt Darmstadt
Object-Oriented Thinking
Object-Oriented Thinking
Class-Responsibility-Collaboration Cards
(A very first glimpse of object-oriented analysis and
design.)
A First Glimpse on OO Analysis and Design.
Object-Oriented Thinking | 3
other classes
Class Collaborations
<collaborator A>
<classname>
<collaborator B>
Responsibilities ...
<responsibility A>
<responsibility B>
... short eng.
sentences
Class-Responsibility-Collaboration (CRC) cards help to
discuss object-oriented designs.
Object-Oriented Thinking | 5
Class Collaborations
Class Collaborations
Square
Text
Responsibilities
Responsibilities
Class Collaborations
Responsibilities
Circle
Responsibilities
Setup
For each potential class, we create a CRC card.
Object-Oriented Thinking | 9
Class Collaborations
PDFDocument
Class Collaborations
Responsibilities
Figure
Responsibilities
Class Collaborations
SVGDocument
Responsibilities
Setup
We then identify responsibilities and collaborators.
Object-Oriented Thinking | 10
Class Collaborations
Class Collaborations
Square
Text
Responsibilities
Responsibilities
Maintain the
Maintain the text
squares data
Class Collaborations
Responsibilities
Circle
Maintain the Responsibilities
triangles data Maintain the
circles data
We then identify responsibilities and collaborators.
Object-Oriented Thinking | 11
Class Collaborations
PDFDocument
Class Collaborations
Responsibilities
Figure Create a .pdf
file
Responsibilities
Maintain a list of
shapes
Class Collaborations
SVGDocument
Responsibilities
Create a .svg file
We incrementally refine our cards.
Object-Oriented Thinking | 12
Class Collaborations
PDFDocument
Class Collaborations
Responsibilities
Figure Create ...
Save a figure to a
Responsibilities
.pdf file
Maintain a list of
shapes
Class Collaborations
SVGDocument
Responsibilities
Create ...
Save a figure to a
.svg file
We incrementally refine our cards.
Object-Oriented Thinking | 13
Class Collaborations
PDFDocument
PDFDocBuilder
Class Collaborations
Responsibilities
Figure Save a figure to a
.pdf file
Responsibilities
Maintain a list of
shapes
Class Collaborations
SVGDocument
SVGDocBuilder
Responsibilities
Save a figure to a
.svg file
We then identify responsibilities and collaborators.
Object-Oriented Thinking | 14
Class Collaborations
Figure
PDFDocBuilder
Text
Class Collaborations
Text
Responsibilities Circle
Figure Save a figure to a Triangle
Circle
.pdf file Square
Responsibilities Triangle
Maintain a list of Square
shapes
Class Collaborations
How do we Figure
SVGDocBuilder
support this? Text
Responsibilities Circle
Save a figure to a Triangle
.svg file Square
We then identify responsibilities and collaborators.
Object-Oriented Thinking | 15
Class Collaborations
Class Collaborations
Square
Text
Responsibilities
Responsibilities
Maintain the
Maintain the text
squares data
Class Collaborations
Responsibilities
Circle
Maintain the Responsibilities
triangles data Maintain the
circles data
We then identify responsibilities and collaborators.
Object-Oriented Thinking | 16
Class Collaborations
Shape N/A
Class Collaborations
Square
Responsibilities
Abstract over Responsibilities
Class Collaborations
shapes Maintain the
Circle
squares data
Class
Responsibilities Collaborations
MaintainTthe
riangle
circles data
Class
Responsibilities Collaborations
Maintain theText
triangles data
Responsibilities
Maintain the text
Specific for class-based
languages
We then identify responsibilities and collaborators.
Object-Oriented Thinking | 17
MaintainTthe Color
riangle
circles data
Class
Responsibilities Collaborations
Maintain theText Color
triangles data
Responsibilities
Maintain the text
Object-Oriented Thinking | 18
DXFDocBuilder
Bzier curve
JPEGDocBuilder
Circle
SVGDocBuilder
BMPDocBuilder
Square
Evolving the Application
Object-Oriented Thinking | 21
DXFDocBuilder
BMPDocBuilder
Square
An Example SVG file
Object-Oriented Thinking | 22
A circle is
2
3
[...]! represented using
<svg version="1.1" viewBox="183 216 143 148" width="143pt" height="148pt">!
4 [...]! an ellipse.
11 <g> !
12
13
Each ...DocBuilder will
<rect x="185" y="218" width="72" height="69" fill="#00009f"/>!
<rect x="185" y="218" width="72" height="69" stroke="black" .../>!
14 contain quite some
<ellipse cx="270" cy="327.5" rx="36.000072" ry="34.500084" fill="#2d4141"/>!
15 <ellipse cx="270" cy="327.5" rx="36.000072" ry="34.500084" stroke="black" .../>!
16 domain logic.
<path d="M 252 241 L 288 310 L 324 241 Z" fill="#ffeb00"/>!
17 <path d="M 252 241 L 288 310 L 324 241 Z" stroke="black" .../>!
18 </g>!
19 </svg>
No direct
support for
triangles.
We then identify responsibilities and collaborators.
Object-Oriented Thinking | 23
Class Collaborations
Figure
PDFDocBuilder
Text
Class Collaborations
Responsibilities
TextThis solution does not Circle
Figure Save a figure to a Triangle
Circle
facilitate software
.pdf file Square
Responsibilities Triangle
Maintain a list of
evolution!
Square
shapes !
We need to think
Class again Collaborations
about the collaborations Figure
SVGDocBuilder
and responsibilities! Text
Responsibilities Circle
Save a figure to a Triangle
.svg file Square
There are some things to consider.
Object-Oriented Thinking | 24
Class Collaborations
If this list gets too long, its probably
Names do matter!
time to split up the class.
Responsibilities If you have cyclic collaboration
If this list gets too long, its probably dependencies its time to think about
time to split up the class. introducing abstractions.
The responsibilities a class has
should be related.
A new class with new responsibilities and collaborators.
Object-Oriented Thinking | 25
Class Collaborations
Text
Figure Class Collaborations
Circle Canvas
Responsibilities Triangle PDFDocBuilder
Maintain a list of Square Responsibilities
shapes
Save figure as
.pdf file
act as a Canvas
Class Collaborations
Color
Canvas
Class Collaborations
Responsibilities Canvas
SVGDocBuilder
draw text, lines,
bzier curves, Responsibilities
JPEGDocBuilder Square
DXFDocBuilder Circle
SVGDocBuilder Triangle
PDFDocBuilder
Background Literature
Object-Oriented Thinking | 28
The International
A Laboratory For Teaching
Conference on Object Object-Oriented Thinking
Press, 1989 anthropomorphic perspective necessary for concepts to novices or the subtleties of a
object-oriented design. We introduce CRC complicated design to experienced object
cards, which characterize objects by class name, programmers.
responsibilities, and collaborators, as a way of
giving learners a direct experience of objects. Rather than try to make object design as much
We have found this approach successful in like procedural design as possible, we have found
teaching novice programmers the concepts of that the most effective way of teaching the
objects, and in introducing experienced idiomatic way of thinking with objects is to
programmers to complicated existing designs. immerse the learner in the object-ness of the
material. To do this we must remove as much
familiar material as possible, expecting that
1. Problem details such as syntax and programming
environment operation will be picked up quickly
The most difficult problem in teaching object- enough once the fundamentals have been
oriented programming is getting the learner to thoroughly understood.
give up the global knowledge of control that is
possible with procedural programs, and rely on It is in this context that we will describe our
the local knowledge of objects to accomplish perspective on object design, its concrete
their tasks. Novice designs are littered with manifestation, CRC (for Class, Responsibility,
regressions to global thinking: gratuitous global and Collaboration) cards, and our experience
variables, unnecessary pointers, and using these cards to teach both the fundamentals
inappropriate reliance on the implementation of and subtleties of thinking with objects.
other objects.
42
A common pitfall in object-oriented design is the
inheritance relation.
Object-Oriented Thinking | 31
42
A common pitfall in object-oriented design is the
inheritance relation.
Object-Oriented Thinking | 32
No.
A common pitfall in object-oriented design is the
inheritance relation.
Object-Oriented Thinking | 34
Low Coupling
High Cohesion
Single Responsibility Principle
Dont repeat yourself
No cyclic dependencies
Liskov Substitution Principle
Open-Closed Principle
...
Goal of the Lecture | 38