Professional Documents
Culture Documents
A Laboratory For Teaching Object Oriente
A Laboratory For Teaching Object Oriente
Object-Oriented Thinking
It is difficult to introduce both novice and reduces to teaching the design of objects. We
experienced procedural programmers to the focus on design whether we are teaching basic
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.
One of the distinguishing features of object As we currently use them, all the information for
design is that no object is an island. All objects an object is written on a 4” x 6” index card.
stand in relationship to others, on whom they rely These have the advantages that they are cheap,
for services and control. The last dimension we portable, readily available, and familiar. Figure 1
use in characterizing object designs is the shows an idealized card. The class name appears
collaborators of an object. We name as underlined in the upper-left hand corner, a bullet-
collaborators objects which will send or be sent
messages in the course of satisfying
responsibilities. Collaboration is not necessarily ClassName
Collaborators
a symmetric relation. For example in Smalltalk- ...
80[*1,View and Controller operate as near equals Responsibilities
(see example below) while Orderedcollection ...
offers a service with little regard or even
awarenessof its client.
Transform
nates.
coordi-
I
Controller
Model
Controller
I
Design with the cards tends to progress from
knowns to unknowns, as opposed to top-down or
bottom up. We have observed two teams arriving
view
Interpret user input. Model at essentially the same design through nearly
Distribute control. opposite sequences, one starting with device
drivers, the other with high-level models. The
problem demanded a certain set of capabilities
which both teams discovered in the course of
fulfilling the requirements of the design.
Mode/
Maintain problem
related info. We suggest driving a design toward completion
Broadcast change with the aid of execution scenarios. We start
notification.
with only one or two obvious cards and start
playing “what-if”. If the situation calls for a
responsibility not already covered by one of the
Figure 2. CRC-cardsdescribingthe responsibilitiesand objects we either add the responsibility to one of
collaborationsof Smalltalk’sModel,ViewandController. the objects, or create a new object to address that
list of responsibilities appears under it in the left responsibility. If one of the object becomes too
two-thirds of the card, and the list of cluttered during this process we copy the
collaborators appears in the right third. information on its card to a new card, searching
for more concise and powerful ways of saying
Figure 2 shows an example taken from the what the object does. If it is not possible to
Smalltalk- image, the much-misunderstood shrink the information further, but the object is
model-view-controller user interface framework. still too complex, we create a new object to
We have deliberately shown only a portion of the assumesome of the responsibilities.
responsibilities each of these objects assumesfor
clarity of exposition. Note that the cards are We encourage learners to pick up the card whose
placed such that View and Controller are role they are assuming while “executing” a
overlapping (implying close collaboration) and scenario. It is not unusual to see a designer with
placed above Model (implying supervision.) We a card in each hand, waving them about, making
find these and other informal groupings aid in a strong identification with the objects while
comprehending a design. Parts, for example, are describing their collaboration.
often arranged below the whole. Likewise,
refinements of an abstraction can be collected We stress the importance of creating objects not
and handled as a single pile of cards with the to meet mythical future needs, but only under the
most abstract card on top where it can represent demands of the moment. This ensures that a
the rest. design contains only as much information as the
designer has directly experienced, and avoids
The ability to quickly organize and spatially premature complexity. Working in teams helps
address index cards proves most valuable when a here because a concerned designer can influence
design is incomplete or poorly understood. We team members by suggesting scenarios aimed
have watched designers repeatedly refer to a card specifically at suspected weaknesses or
they intended to write by pointing to where they omissions.
will put it when completed.
L
I Transaction
screen
Event
The RemoteDataBase drives the communication Displays prompts. Action
lines and interprets data transmitted across them. I Disoatches Events
tb Actions.
1
It creates Account objects and consumes
Transaction objects.
Event
I Screen
Queues Signals. CardReader
I
Isolates H/w from Dispenser
user-interface. RemoteDt3