The Object Primer Second Edition The App
The Object Primer Second Edition The App
The Object Primer Second Edition The App
Secon d Edition
Th e Ap p lica t ion Develop er’s Guid e t o
Object Orien t a t ion a n d t h e UML
Sc o t t W. Am b l e r
PUBLISHED BY THE PRESS SYNDICATE OF THE UNIVERSITY OF CAMBRIDGE
Th e Pitt Bu ild in g, Tru m p in gton Street, Cam brid ge, Un ited Kin gd om
A catalog record for this book is available from the British Library.
Fo rew o rd xvii
Preface xix
Ackn o w ledgm en ts xxiii
ix
x The Object Prim er
Ch apter 10 • Puttin g It All To geth er: So ftw are Pro cess 427
10.1 W h at Is So Differen t Abou t Object-Orien ted Develop m en t? 429
10.2 W h at Is a Software Process? 430
10.3 W h y Do You Need a Software Process? 431
Con ten ts xv
Ch a p t er 1
In t ro d u c t i o n
1
2 The Object Prim er
D EFIN ITION
Pa ra d igm . (pronounced para-dime) An overall strategy or viewpoint for doing
things. A paradigm is a specific mindset.
Ch a pter 1 • In troduction 3
Object
Object
Functions
and Data
Procedures Object Object
th e real world , stu d en ts kn ow th in gs (th ey h ave n am es, ad d resses, birth Figure 1-1.
d ates, telep h on e n u m bers, an d so on ) an d th ey d o th in gs (en roll in Comparing the
cou rses, d rop cou rses, an d p ay tu ition ). Professors also kn ow th in gs (th e structured and
cou rses th ey teach an d th eir n am es) an d th ey d o th in gs (in p u t m arks an d object-oriented
paradigms
m ake sch ed u le req u ests). From a system s p ersp ective, room s kn ow th in gs
(th e bu ild in g th ey’re in an d th eir room n u m ber) an d sh ou ld be able to
d o th in gs, too (su ch as tell you wh en th ey are available an d en able you
to reserve th em for a certain p eriod of tim e). Cou rses also kn ow th in gs
(th eir title, d escrip tion , an d wh o is takin g th e cou rse) an d sh ou ld be able
to d o th in gs (su ch as lettin g stu d en ts en roll in th em or d rop th em ).
To im plem en t th is system , we would defin e a collection of classes (a class
is a gen eric represen tation of sim ilar objects) th at in teract with each oth er.
For exam ple, we would h ave “Course,” “Studen t,” “Professor,” an d “Room ”
classes. Th e collection of th ese classes would m ake up our application ,
wh ich would in clude both th e fun ction ality (th e program ) an d th e data.
As you can see, th e OO ap p roach resu lts in a com p letely d ifferen t view For ind ivid ua ls,
of wh at an ap p lication is all abou t. Rath er th an h avin g a p rogram th at OO is a whole new
accesses a d atabase, we h ave an ap p lication th at exists in wh at is called wa y t o t hink.
For orga niza t ions,
an object sp ace. Th e object space is wh ere both th e p rogram an d th e d ata
OO req uires a
for th e ap p lication resid e. I d iscu ss th is con cep t in fu rth er d etail in Ch ap - com p let e cha nge
ter 5 bu t, for n ow, th in k of th e object sp ace as virtu al m em ory. in it s syst em
d evelop m ent
cult ure.
1.2 How Is Th is Book Org a n ized?
The Object Prim er covers leadin g-edge OO tech n iques an d con cepts th at
h ave been proven in th e developm en t of real-world application s. It covers
in detail wh y you sh ould learn th is n ew approach called object orientation,
requirem en ts tech n iques, such as use cases an d CRC m odelin g, OO
4 The Object Prim er
D EFIN ITION S
Cla ss. A template from which objects are created (instantiated). Although in
the real world Doug, Wayne, and Bill are all “ student objects,” we would model
the class “ Student” instead.
Object sp a ce. The memory space, including all accessible permanent storage,
in which objects exist and interact with one another.
Object . A person, place, thing, concept, event, screen, or report. Objects both
know things (that is, they have data) and they do things (that is, they have
functionality).
Object -orient ed p a ra d igm . A development strategy based on the concept of
building systems from reusable components called objects.
OO. An acronym used interchangeably for two terms: Object-oriented and
object orientation. For example, when we say OO programming, we really
mean object-oriented programming. When we say this is a book that describes
OO, we really mean this it is a book that describes object orientation.
Th e Object Prim er con cepts, OO an alysis an d design usin g th e UML m odelin g tech n iques,
covers everyt hing OO program m in g, OO testin g, an d th e OO software process. Th e book
you need to know to en ds with a discussion of h ow to con tin ue your learn in g process, in cludin g
get you st a rt ed in
description s of com m on object-orien ted tech n ologies an d tech n iques you
OO d evelop m ent .
m igh t wan t to con sider applyin g on software projects.
Figu re 1-2 d ep icts th e organ ization of The Object Prim er, sh owin g th e
in d ivid u al ch ap ters an d th e relation sh ip s between th em . Table 1-1 su m -
m arizes th e con ten ts of each ch ap ter. On th e left sid e of th e d iagram are
th e ch ap ters th at d escribe th e fu n d am en tal activities of th e software
p rocess, su ch as gath erin g req u irem en ts, object-orien ted an alysis, an d
object-orien ted p rogram m in g. Th e arrows between th e boxes rep resen t
th e gen eral relation sh ip s between th e ch ap ters: you see th e ch ap ters
d escribin g gath erin g req u irem en ts, valid atin g req u irem en ts, an d object-
orien ted an alysis are closely related to on e an oth er. Ch ap ter 9 covers
object-orien ted testin g an d d escribes testin g tech n iq u es th at sh ou ld be
u sed to valid ate you r an alysis, d esign , an d p rogram m in g efforts. Alon g
th e righ t-h an d sid e of Figu re 1-2 are listed several “su p p ortin g” ch ap ters,
ch ap ters th at p resen t m aterial th at is critical to you r u n d erstan d in g of
th e object-orien ted p arad igm .
D EFIN ITION
Unified Mod eling La ngua ge (UML). The definition of a standard modeling
language for object-oriented software, including the definition of a modeling
notation and the semantics for applying it as defined by the Object Manage-
ment Group (OMG).
Ch a pter 1 • In troduction 5
Object-Oriented Object-Oriented
Analysis Concepts
(Chapter 6) (Chapter 5)
Figure 1-2.
The organization of
1.3 How to Rea d Th is Book this book
Ch a pter Description
2: A New Software Paradigm Discussion of the advantages and disadvantages of object ori-
entation, why objects are here to stay, and an overview of the
software process.
10: Object-Oriented Software Process Overview of the Object-Oriented Software Process (OOSP)
and the enhanced lifecycle of the Unified Process.
11: Where to Go From Here Discussion of what you need to do to continue your OO
learning process, including a description of leading object
technologies and techniques such as Java, Enterprise Java-
Beans (EJB), C++, and component-based development.
Ch a pter 1 • In troduction 7
D EFIN ITION
Full lifecycle object -orient ed t est ing (FLOOT). A testing methodology for
object-oriented development that comprises testing techniques that, taken
together, provide methods to verify that your application works correctly at
each stage of development.
St ud ent s
Like th e first grou p of p eop le, you sh ou ld also read th is book from cover
to cover. Fu rth erm ore, you sh ou ld read th is book two or th ree weeks
before you r m id term test on object orien tation , an d n ot th e n igh t before
th e exam . Th is stu ff takes a wh ile to sin k in (actu ally it takes m u ch
lon ger th an a few weeks, bu t th ere’s on ly so m u ch tim e in a sch ool term ).
Ch a p t er 6
D e t e rm i n i n g W h a t t o
Bu i l d : Ob je c t -Ori e n t e d
An a l y si s
How to develop a system use case model from an essential use case model
How to develop sequence diagrams
How to develop a conceptual class model from a domain model
How to develop activity diagrams
How to develop a user interface prototype
How to evolve your supplementary specification
How to apply the Object Constraint Language (OCL)
How to apply analysis patterns
How to write user documentation
How to apply packages on your diagrams
Your requirements model, although effective for understanding what your users
want to have built, is not as effective at understanding what will be built.
Object-oriented analysis techniques, such as system use case modeling, sequence
diagramming, class modeling, activity diagramming, and user interface
prototyping are used to bridge the gap between requirements and system design.
181
182 The Object Prim er
Req uirem ent s Th e p u rp ose of an alysis is to u n d erstan d wh at will be bu ilt. Th is is sim ilar
engineering to req u irem en ts gath erin g, d escribed in Ch ap ter 3, th e p u rp ose of wh ich
focuses on
is to d eterm in e wh at you r u sers wan t to h ave bu ilt. Th e m ain d ifferen ce
und erst a nd ing
is th at th e focu s of req u irem en ts gath erin g is on u n d erstan d in g you r
users a nd t heir
usa ge, wherea s u sers an d th eir p oten tial u sage of th e system , wh ereas th e focu s of an aly-
a na lysis focuses sis sh ifts to u n d erstan d in g th e system itself.
on und erst a nd ing Figu re 6 -1 dep icts th e m ain artifacts of you r an alysis efforts an d th e
wha t need s t o be relation sh ip s between th em . Th e solid boxes in dicate m ajor an alysis arti-
built . facts, wh ereas th e dash ed boxes rep resen t you r m ajor req u irem en ts arti-
facts. As with th e p reviou s Figu re 3-1, th e arrows rep resen t “drives”
relation sh ip s; for exam p le, you see th at in form ation con tain ed in you r
CRC m odel affects in form ation in you r class m odel an d vice versa. Figu re
6 -1 h as th ree im p ortan t im p lication s. First, an alysis is an iterative p rocess.
Essential
Use Case
Use Case
Model
Model
Sequence Activity
Business Rules
Diagram Diagram
Class Model
CRC Model
(Analysis)
Secon d, taken togeth er, req u irem en ts gath erin g an d an alysis are h igh ly
in terrelated an d iterative. As you see in Ch ap ter 7, wh ich describes object-
orien ted design tech n iq u es, an alysis an d design are sim ilarly in terrelated
an d iterative. Th ird, th e “essen tial” m odels, you r essen tial u se case m odel
an d you r essen tial u ser in terface p rototyp e, evolve in to corresp on din g
an alysis artifacts—resp ectively, you r u se case m odel an d u ser in terface
p rototyp e. W h at isn ’t as obviou s is th at you r Class Resp on sibility Collabo-
rator (CRC) m odel evolves in to you r an alysis class m odel.
You r u se case m od el d escribes h ow you r u sers work with you r system ,
reflectin g th e bu sin ess ru les p ertin en t to you r system , as well as asp ects
of you r u ser in terface m od el. You can u se eith er Un ified Mod elin g Lan -
gu age (UML) seq u en ce d iagram s or UML activity d iagram s to flesh ou t
an d verify th e logic con tain ed in you r u se cases. Fu rth erm ore, you see
th at seq u en ce d iagram s act as a brid ge to you r class m od el, wh ich d ep icts
th e static stru ctu re of th e classes from wh ich you r system will be bu ilt.
You r u ser in terface m od el, in clu d in g you r u ser in terface p rototyp e an d
you r u ser in terface flow d iagram (see Ch ap ter 3), also d rives ch an ges to
you r class m od el.
An im p ortan t con cep t to n ote abou t Figu re 6 -1, an d sim ilarly Figu res Ana lysis is a n
7-1 an d 8-1, is th at every p ossible “d rives” relation sh ip is n ot sh own . For it era t ive p rocess.
exam p le, as you are d evelop in g you r u se case m od el, m ost likely you will
realize you are m issin g a featu re in you r u ser in terface, yet a relation sh ip
d oesn ’t exist between th ese two artifacts. From a p u re/ acad em ic p oin t of
view, wh en you realize you r u se case m od el con flicts with you r u ser-
in terface m od el, you sh ou ld first con sid er wh at th e p roblem is, u p d ate
you r u se case m od el ap p rop riately, p rop agate th e ch an ge to you r essen -
tial u se case m od el, an d th en to you r essen tial u ser in terface m od el, an d ,
fin ally, in to you r u ser in terface m od el. Yes, you m ay, in fact, take th is
rou te. Ju st as likely, an d p robably m ore so, is th at you will, in stead ,
u p d ate both you r u se case m od el an d u ser in terface m od el togeth er, an d
th en p rop agate th e ch an ges to th e corresp on d in g req u irem en ts artifacts.
Th is is an im p ortan t asp ect of iterative d evelop m en t. You d on ’t n ecessar-
ily work in a d efin ed ord er; in stead , you r work reflects th e relation sh ip s
between th e artifacts you evolve over tim e.
A secon d im p ortan t con cep t is th e d ifferen ce between a m od el an d a
d iagram . A d iagram is a p ictu re —typ ically con sistin g of bu bbles con -
n ected by lin es d ocu m en ted with labels—th at d ep icts an abstraction of
a p ortion or an asp ect of a system . A m od el is also an abstraction ,
alth ou gh it is m ore robu st becau se it con sists of zero or m ore d iagram s,
p lu s associated d ocu m en tation . For exam p le, a class m od el is com p osed
of a UML class d iagram an d th e sp ecification s of th e classes an d associa-
tion s d ep icted on th at d iagram , wh ereas a CRC m od el is a collection of
CRC card s.
184 The Object Prim er
D EFIN ITION S
Act ivit y d ia gra m . A UML diagram used to model high-level business processes or the transitions
between states of a class (in this respect, activity diagrams are effectively specializations of state chart
diagrams).
Cla ss d ia gra m . Shows the classes of a system and the associations between them.
Cla ss m od el. A class diagram and its associated documentation.
Cla ss Resp onsibilit y Colla bora t or (CRC) ca rd . A standard index card that has been divided into
three sections: one indicating the name of the class the card represents, one listing the responsibilities
of the class, and the third listing the names of the other classes with which this one collaborates to ful-
fill its responsibilities.
Cla ss Resp onsibilit y Colla bora t or (CRC) m od el. A collection of CRC cards that model all or part
of a system.
Dia gra m . A visual representation of a problem or solution to a problem.
Essent ia l use ca se. A simplified, abstract, generalized use case that captures the intentions of a user
in a technology and implementation independent manner.
Essent ia l use ca se m od el. A use case model comprised of essential use cases.
Essent ia l user int erfa ce p rot ot yp e. A low-fidelity prototype of a system’s user interface that mod-
els the fundamental, abstract characteristics of a user interface.
Mod el. An abstraction describing a problem domain and/or a solution to a problem domain. Tradi-
tionally models are thought of as diagrams plus their corresponding documentation, although non-
diagrams, such as interview results and collections of CRC cards, are also considered to be models.
Project st a kehold er. Anyone who could be materially affected by the implementation of a new sys-
tem or application.
Prototype. A simulation of an item, such as a user interface or a system architecture, the purpose of which
is to communicate your approach to others before significant resources are invested in the approach.
Sequence d ia gra m . A diagram that models the sequential logic, in effect, the time ordering of messages.
Use ca se. A sequence of actions that provide a measurable value to an actor.
Use ca se d ia gra m . A diagram that shows use cases, actors, and their interrelationships.
Use ca se m od el. A model comprised of a use case diagram, use case definitions, and actor defini-
tions. Use case models are used to document the behavior requirements of a system.
User int erfa ce (UI). The user interface of software is the portion the user directly interacts with,
including the screens, reports, documentation, and software support (via telephone, electronic mail,
and so on).
User int erfa ce flow d ia gra m . A diagram that models the interface objects of your system and the
relationships between them. Also know as an interface-flow diagram, a windows navigation diagram,
or an interface navigation diagram.
User int erfa ce p rot ot yp e. A prototype of the user interface (UI) of a system. User interface proto-
types could be as simple as a hand-drawn picture or a collection of programmed screens, pages, or
reports.
Ch a pter 6 • Determ in in g Wh a t to Bu ild: Object-Orien ted An a lysis 185
D EFIN ITION S
Ext end a ssocia t ion. A generalization relationship where an extending use case
continues the behavior of a base use case. The extending use case accomplishes
this by inserting additional action sequences into the base use case sequence.
This is modeled using a use case association with the <<extend>> stereotype.
Includ e a ssocia t ion. A generalization relationship denoting the inclusion of
the behavior described by a use case within another use case. This is modeled
using a use case association with the <<include>> stereotype Also known as a
“ uses” or a “ has-a” relationship.
Ch a pter 6 • Determ in in g Wh a t to Bu ild: Object-Orien ted An a lysis 187
continued on page 90
188 The Object Prim er
Student System
1. The student wants to enroll in a seminar. 3. The system verifies the student is eligible to enroll
2. The student inputs his name and student number in seminars at the university, according to business
into the system via “ UI23 Security Login Screen.” rule “ BR129 Determine Eligibility to Enroll.”
4. The system displays “ UI32 Seminar Selection
Screen,” which indicates the list of available seminars.
5. The student indicates the seminar in which she 6. The system validates the student is eligible to
wants to enroll. enroll in the seminar, according to the business
rule “ BR130 Determine Student Eligibility to Enroll
in a Seminar.”
7. The system validates the seminar fits into the
existing schedule of the student, according to the
business rule “ BR143 Validate Student Seminar
Schedule.”
8. The system calculates the fees for the seminar
based on the fee published in the course catalog,
applicable student fees, and applicable taxes.
Apply business rules “ BR 180 Calculate Student
Fees” and “ BR45 Calculate Taxes for Seminar.”
9. The system displays the fees via “ UI33 Display
Seminar Fees Screen.”
10. The system asks the student whether she still
wants to enroll in the seminar.
11. The student indicates she wants to enroll in the 12. The system enrolls the student in the seminar.
seminar. 13. The system informs the student the enrollment
was successful via “ UI88 Seminar Enrollment Sum-
mary Screen.”
14. The system bills the student for the seminar,
according to business rule “ BR100 Bill Student for
Seminar.”
15. The system asks the student if she wants a
printed statement of the enrollment.
16. The student indicates she wants a printed 17. The system prints the enrollment statement
statement. “ UI89 Enrollment Summary Report.”
18. The use case ends when the student takes the
printed statement.
Figure 6-3.
Basic course of
action for “ Enroll in
Seminar” written in
action-response style
190 The Object Prim er
6.1.2 Reuse in Use Ca se Mod els: <<ext end >>, <<includ e>>,
a nd Inherit a nce
You ca n ind ica t e On e of you r goals d u rin g an alysis is to id en tify p oten tial op p ortu n ities
p ot ent ia l for reu se, a goal you can work toward as you are d evelop in g you r u se case
op p ort unit ies for m od el. Poten tial reu se can be m od eled th rou gh fou r gen eralization rela-
reuse on your use
tion sh ip s su p p orted by th e UML u se case m od els: exten d relation sh ip s
ca se m od els
between u se cases, in clu d e relation sh ip s between u se cases, in h eritan ce
between u se cases, an d in h eritan ce between actors.
Figure 6-4.
The opportunities
for reuse in use case
models
Registrar
Enroll in Enroll in
<<include>>
University Seminar
Student
<<extend>>
International
Student
Figure 6-5.
4. The system displays “ UI43 Student Information Entry.” [Extension Point: Documenting an
UC34 Enroll International Student In University.] extension point
5. The student… within a use case
192 The Object Prim er
D EFIN ITION S
Ba se use ca se. A use case extended by another via an extend association.
Ext end ing use ca se. A use case that extends another use case via an extend
association.
Ext ension p oint . A marker in a use case where extension is allowed.
“En roll in Un iversity” in clu des th e u se case “En roll in Sem in ar”; th e n ota-
tion for doin g so is sim p ly a n orm al u se case association with th e stereo-
typ e of <<in clu de>>. Figu re 6 -6 p resen ts an exam p le of h ow you wou ld
in dicate wh ere th e u se case is in clu ded in th e logic of th e in clu din g u se
case. Sim ilar to callin g a fu n ction or in vokin g an op eration with in sou rce
code, isn ’t it? Object-orien ted p rogram m in g is covered in Ch ap ter 8.
You u se in clu d e association s wh en ever on e u se case n eed s th e beh av-
ior of an oth er. In trod u cin g a n ew u se case th at en cap su lates sim ilar logic
th at occu rs in several u se cases is q u ite com m on . For exam p le, you m ay
d iscover th at several u se cases n eed th e beh avior to search for an d th en
u p d ate in form ation abou t stu d en ts, in d icatin g th e p oten tial n eed for an
“Up d ate Stu d en t Record ” u se case in clu d ed by th e oth er u se cases.
As you wou ld exp ect, th e u se case “En roll in Un iversity” sh ou ld list
“UC17 En roll in Sem in ar” in its “In clu d es” list. W h y sh ou ld you both er
m ain tain in g an “In clu d es” an d an “Exten d s” list in you r u se cases? Th e
an swer is sim p le: You r u se cases sh ou ld stan d on th eir own ; you sh ou ldn ’t
exp ect p eop le to h ave you r u se case diagram in fron t of th em . Yes, it
wou ld be n ice if everyon e h as access to th e u se case d iagram becau se it
also con tain s th is in form ation , bu t th e reality is th at som etim es you u se
d ifferen t tools to d ocu m en t each p art of you r m od el. For exam p le, you r
d iagram s cou ld be d rawn u sin g a d rawin g p ackage an d you r u se cases
d ocu m en ted in a word p rocessor. Som e of you r p roject stakeh old ers m ay
h ave access to th e word p rocessor you are u sin g, bu t n ot th e d rawin g
p ackage. Th e m ain d isad van tage of th is ap p roach is you n eed to m ain -
tain th ese two lists in p arallel with th e d iagram , th e d an ger bein g th ey
m ay becom e u n syn ch ron ized .
Figure 6-6.
Indicating the 8. The student indicates the seminar(s) she wants to take via the use case
inclusion of a UC 17 Enroll in Seminar.
use case 9. The student…
Ch a pter 6 • Determ in in g Wh a t to Bu ild: Object-Orien ted An a lysis 193
6.1.2.3 Inheritance
Use cases can in h erit from oth er u se cases, offerin g a th ird op p ortu n ity to Use ca ses m a y
in dicate p oten tial reu se. Figu re 6 -4 dep icts an exam p le of th is, sh owin g inherit from ot her
th at “En roll Fam ily Mem ber in Un iversity” in h erits from th e “En roll In use ca ses.
Un iversity” u se case. In h eritan ce between u se cases is n ot as com m on as
eith er th e u se of exten d or in clu de association s, bu t it is still p ossible. Th e
in h eritin g u se case wou ld com p letely rep lace on e or m ore of th e cou rses
of action of th e in h erited u se case. In th is case, th e basic cou rse of action
is com p letely rewritten to reflect th at n ew bu sin ess ru les are ap p lied wh en
th e fam ily m em ber of a p rofessor is en rollin g at th e u n iversity. Fam ily
m em bers are allowed to en roll in th e sch ool, regardless of th e m arks th ey
earn ed in h igh sch ool; th ey don ’t h ave to p ay an y en rollm en t fees, an d
th ey are given top p riority for en rollm en t in th e u n iversity.
In h eritan ce between use cases sh ould be applied wh en ever a sin gle con di- Ap p ly inherit a nce
tion , in th is case, th e studen t is a fam ily m em ber of a professor, would result bet ween use ca ses
in th e defin ition of several altern ate courses. With out th e option to defin e when a single
cond it ion would
an in h eritin g use case, you n eed to in troduce an altern ate course to rework
result in severa l
th e ch eck of th e studen t’s h igh -sch ool m arks, th e ch argin g of en rollm en t a lt erna t e courses.
fees, an d for prioritization of wh o is allowed to en roll in th e given sem ester.
Th e in h eritin g u se case is m u ch sim p ler th an th e u se case from wh ich
it in h erits. It sh ou ld h ave a n am e, d escrip tion , an d id en tifier, an d it
sh ou ld also in d icate from wh ich u se case it in h erits in th e “In h erits
From ” section . In section s th at you rep lace, you m ay n eed to rewrite th e
p recon d ition s, p ostcon d ition s, or cou rses of action . If som eth in g is n ot
rep laced , th en leave th at section blan k, assu m in g it is in h erited from th e
p aren t u se case (you m igh t wan t to p u t text, su ch as “see p aren t u se
case,” in th e section ).
Th e fourth opportun ity for in dicatin g poten tial reuse with in use case Act ors m a y inherit
m odels occurs between actors: An actor on a use case diagram can in h erit from ot her a ct ors.
from an oth er actor. An exam ple of th is is sh own in Figure 6-4, wh ere th e
“In tern ation al Studen t” actor in h erits from “Studen t.” An in tern ation al stu-
den t is a studen t, th e on ly differen ce bein g h e or sh e is subject to differen t
rules an d policies (for in stan ce, th e in tern ation al studen t pays m ore in
tuition ). Th e stan dard UML n otation for in h eritan ce, th e open -h eaded
arrow, is used an d th e advice presen ted about th e appropriate use of in h eri-
tan ce still applies: It sh ould m ake sen se to say th e in h eritin g actor is or is
like th e in h erited actor.
D EFIN ITION S
Ma jor user int erfa ce elem ent . A large-grained item, such as a screen, HTML
page, or report.
Minor user int erfa ce elem ent . A small-grained item, such as a user input
field, menu item, list, or static text field.
Sup p lem ent a ry sp ecifica t ion. An artifact where all requirements not contained
in your use case model, user interface model, or domain model are documented.
198 The Object Prim er
student number
isEligible(name, studentNumber)
3. System verifies student <<create>>
theStudent
theStudent
<<destroy>> Note: Need to
X flesh this message
out more.
<<create>>
4. System displays seminar list
selection
5. Students picks seminar
isEligibleToEnroll(theStudent) qualifications()
6. System determines eligibility to enroll
getSchedule()
determineFit(seminar)
7. System determines schedule fit
<<create>>
9. System displays fees
10. System verifies student wishes to enroll
11. Students indicates yes. verification
Figure 6-7.
A UML sequence
diagram for the basic
course of action for
Figure 6-2
200 The Object Prim er
D EFIN ITION S
Anonym ous object . An object appearing on the diagram that hasn’t been
given a name; instead, the label is simply an indication of the class, such as
“ : Invoice.”
Cla ssifier. A mechanism that describes behavioral or structural features. Classi-
fiers include use cases, classes, interfaces, and components.
Lifeline. Represents, in a sequence diagram, the life span of an object during
an interaction.
Met hod . Something a class or object does. A method is similar to a function or
procedure in structured programming and is often referred to as an operation
or member function in object development.
Messa ge-invoca t ion box. The long, thin, vertical boxes that appear on sequence
diagrams, which represent invocation of an operation on an object or class.
Signa t ure. The combination of the name, parameter names (in order), and
name of the return value (if any) of a method.
St a t ic m et hod . A method that operates at the class level, potentially on all
instances of that class.
St ereot yp e. A stereotype denotes a common usage of a modeling element.
Stereotypes are used to extend the UML in a consistent manner.
Ch a pter 6 • Determ in in g Wh a t to Bu ild: Object-Orien ted An a lysis 201
D EFIN ITION S
C++. A hybrid object-oriented programming language that adds object-oriented
features to the C programming language.
Const ruct or. A method, typically a static one, whose purpose is to instantiate
and, optionally, initialize an object.
Cont roller. A class that implements business/domain logic, coordinating sev-
eral objects to perform a task.
Dest ruct or. A method whose purpose is to remove an object completely from
memory.
Gold p la t ing. The addition of extraneous features to a system.
Ja va . An object-oriented programming language based on the concept of
“ write once, run anywhere.”
Not e. A modeling construct for adding free-form text to the UML diagrams.
You may have heard terms such as dynamic modeling and static modeling TIP
bantered about by other developers familiar with object-oriented modeling
techniques. You may even have heard arguments about the merits of each Seq uence
style. Dynamic modeling techniques focus on identifying the behavior within Dia gra m s Are
your system. These techniques include sequence diagramming and activity Dyna m ic
diagramming (both of which are described in this chapter) and collaboration
diagramming, described in Chapter 7. Static modeling focuses on the static
aspects of your system, including the classes, their attributes, and the associations
between classes. Class models, described in this chapter, are the main artifact
of static modeling, as are persistence models, which are described in Chapter
7. Both dynamic and static modeling techniques are required to specify an
object-oriented system adequately, which makes the “ dynamic modeling
versus static modeling” debates questionable at best.
Enroll In Seminar
Alternate Course of
Action: Student Does
not Have Prerequisites A Student :EnrollInSeminar :IneligibilityNotice :SeminarDetails seminar:Seminar
<<actor>> <<controller>> <<UI>> <<UI>>
SD #: UC17-01B
isEligibleToEnroll(theStudent)
B.6. System determines ineligibility to enroll
false
<<create>>
B.7. System informs the student of ineligibility
B.8. System informs the student of <<create>>
prerequisites
B.9. Use case resumes at step 4
204 The Object Prim er
tial design . As you can see with th is exam p le, th e lin e between an alysis
an d design is fu zzy with object-orien ted develop m en t; exp erien ced devel-
op ers n ew to objects can take tim e to get u sed to th is. Fin ally, I left th e
“Stu den t” actor in th e diagram , even th ou gh n o direct in teraction occu rs
at th is p oin t becau se th is actor is referred to in th e step s of th e u se case.
1
Stereotyp es in th e UML typ ically begin with a lowercase letter. However, becau se I am
u sin g th e term “UI” for th e stereotyp e label, in stead of “u ser in terface,” I h ave ch osen
to cap italize it. Also, in Ch ap ter 3, I was u sin g th e stereotyp e <<Actor>> in stead of
<<actor>> on th e Class Resp on sibility Collaborator (CRC) card s. I d id th is for two rea-
son s. First, CRC m od els are n ot p art of th e UML an d , th erefore, d on ’t h ave com p ly
with UML p ractices. Secon d , I d id it to sh ow you th e world won ’t en d if you break th e
ru les a bit. I’ve lot track of th e am ou n t of tim e, easily in th e h u n d red s of h ou rs, th at
I’ve wasted in con versation s d u rin g m od elin g session s over n itp icky issu es su ch as th is.
You r goal is to m od el you r system accu rately in a way th at is u n d erstan d able to th e
p eop le in volved ; wh eth er you u se <<Actor>> or <<actor>> as a stereotyp e is barely rele-
van t wh en th e big p ictu re is taken in to con sid eration .
206 The Object Prim er
D EFIN ITION
Tra nsit ory object . An object that is not saved to permanent storage.
208 The Object Prim er
D EFIN ITION
Com p ut er-a id ed syst em engineering (CASE) t ool. Software that supports
the creation of models of software-oriented systems.
2
In th e origin al ed ition of th is book, written in 1995, I argu ed for, an d th en u sed , th e
term “class m od el,” in stead of “object m od el,” for th e sim p le reason th at you u se th em
to m od el classes an d th eir relation sh ip s, n ot objects.
Ch a pter 6 • Determ in in g Wh a t to Bu ild: Object-Orien ted An a lysis 209
D EFIN ITION S
Problem sp a ce. The scope of your business domain being addressed by your
system.
Solut ion sp a ce. The problem space being addressed by your system plus the
nondomain functionality required to implement your system.
n eed ed to actu ally bu ild it. Lu ckily, th ose d etails h ave been cap tu red in
th e n otes taken d own by th e scribe(s) d u rin g CRC m od elin g. Figu re 6 -9
d ep icts th e CRC m od el we d evelop ed in Ch ap ter 3, th e “Secu rityLogon ”
class id en tified in th e seq u en ce d iagram s earlier h as been in trod u ced to
CRC m od el, an d Figu re 6 -10 d ep icts th e UML class d iagram th at wou ld
be created based on th at CRC m od el.
For each card in th e CRC m odel, you create a con crete class in th e class
diagram , with th e exception of cards th at represen t actors (actors exist in th e Fig ure 6 -9 .
real world). Notice h ow th e n am es stayed th e sam e (spaces were rem oved A CRC model for
the university
Professor
Name
Seminar
Address
Phone number
Email address
Salary
Transcript <<UI>>
Provide information
Seminars instructing
**See the prototype** Student
Student <<Actor>> Get student info Seminar
Get seminars student Professor .
Provide information Enroll in Seminar took Enrollment Record
about self Transcript Determine average Seminar
Request to enroll in mark
seminar Name
Output self Student
Request Transcript Seminar number
Professor
Fees
Waiting list
Enrolled students
Enroll in Seminar <<UI>> Instructor
Add student
**See the prototype** Seminar Drop student
Enable seminar search Professor
Display seminar list
Display seminar fees Student
Display professor info
Name Enrollment
Address Record
Phone number
Email address
Student number
Average mark received
SecurityLogon <<UI>> Validate identifying info
Provide list of seminars
**See the prototype** Student taken
Request identifying
info for student
Enrollment Record
EnrollmentRecord
marksReceived
SecurityLogon
<<UI>> getAverageToDate()
enrolled getFinalMark()
acceptStudentID() in enrolled
acceptStudentName()
in
validateStudent()
Student
name Seminar
Transcript
address name
<<UI>>
phoneNumber seminarNumber
emailAddress fees
getStudent() studentNumber on waiting list waitingList
getSeminars() averageMark
determineAverage() addStudent(student)
isEligible (name, dropStudent(student)
output() studentNumber)
getSeminarsTaken()
EnrollInSeminar
<<UI>> instructs
searchForSeminar()
displaySeminarList() Professor
displaySeminarFees() name
displayProfessor() address
phoneNumber
emailAddress
salary
Fig ure 6 -1 0 . getInformation()
A UML class diagram
based on the CRC
model
D EFIN ITION
Concret e cla ss. A class that has objects instantiated from it.
D EFIN ITION S
Bid irectiona l a ssocia tion. An association that may be traversed in both directions.
Unid irect iona l a ssocia t ion. An association that may be traversed in only one
direction.
Visibilit y. The level of access external objects have to an item, such as an
object’s attributes or methods, or even to a class itself.
Mod eling user even tu al u ser in terface d esign . Th e p u rp ose of m od els is to d escribe you r
interfa ce cla sses on system ad eq u ately, rarely to d escribe it th orou gh ly. Yes, I cou ld create
cla ss d ia gra m s d etailed classes for each UI class in m y m od el, bu t wh at valu e wou ld th at
often a d d s a lot of
be? It sou n d s like a lot of work for little retu rn , p articu larly wh en m ore
clutter without
th an en ou gh d etails are in th e u ser in terface m od el alread y. Also, as you
a d d ing m uch
useful inform a tion. can see in Figu re 6 -10, th e UI classes h ave m ad e q u ite a m ess of th e d ia-
gram , req u irin g th e m od elin g of a lot of d ep en d en cies th at ad d sign ifi-
can t clu tter with ou t com m u n icatin g m u ch valu able in form ation . Th is
in form ation cou ld be better record ed as p art of you r u ser in terface
m od el; a sim p le sp read sh eet listin g each m ajor UI elem en t an d th e bu si-
n ess classes on wh ich th ey are d ep en d en t sh ou ld be su fficien t.
Figu re 6 -11 p resen ts a revised version of Figu re 6 -10; th e u ser in terface
classes h ave been rem oved an d th e m u ltip licity of th e association s h ave
been m od eled . Based on wh at th e SMEs tell you an d on th e in form ation
con tain ed in th e n otes you r scribe(s) took as p art of req u irem en ts gath er-
in g, you sh ou ld be able to m ake ed u cated gu esses at th e m u ltip licities of
each association . In Figu re 6 -11, I was able to d eterm in e with certain ty,
based on th is in form ation , th e m u ltip licities for all bu t on e association
an d , for th at on e, I m arked it with a n ote to m yself. Notice m y u se of
q u estion m arks in th e n ote. As m en tion ed in Ch ap ter 5, m y style is to
m ark u n kn own in form ation on m y d iagram s th is way to rem in d m yself
th at I n eed to look in to it.
Mod el com p lex In Figu re 6 -11, I also m od eled a UML con strain t, in th is case “{ord ered
or im p ort a nt FIFO},” on th e association between “Sem in ar” an d “Stu d en t.” Th e basic
concep t s on your id ea is th at stu d en ts are p u t on th e waitin g list on a first-com e, first-ou t
UML d ia gra m s
(FIFO) basis. In oth er word s, th e stu d en ts are p u t on th e waitin g list in
using OCL.
ord er. UML con strain ts are u sed to m od el com p lex an d / or im p ortan t
in form ation accu rately in you r UML d iagram s. UML con strain ts are m od -
eled u sin g th e form at “{con strain t d escrip tion }” form at, wh ere th e con -
strain t d escrip tion m ay be in an y form at, in clu d in g p red icate calcu lu s.
Fowler an d Scott (1997) su ggest th at you focu s on read ability an d u n d er-
stan d ability an d , th erefore, su ggest u sin g an in form al d escrip tion . Con -
strain ts are d escribed in fu rth er d etail in Section 6.6.1.
Ch a pter 6 • Determ in in g Wh a t to Bu ild: Object-Orien ted An a lysis 213
EnrollmentRecord
1 enrolled in 1..* 1..* enrolled in 1
Student marksReceived Seminar
name getAverageToDate() name
address getFinalMark() seminarNumber
phoneNumber fees
{ordered, FIFO}
emailAddress 0..* on waiting list 0..* waitingList
studentNumber addStudent(student)
averageMark 0..* dropStudent(student)
isEligible (name,
studentNumber)
Professor
getSeminarsTaken()
name instructs
address
0..1
phoneNumber
emailAddress
salary
getInformation()
Fig ure 6 -1 1 .
On ce you h ave con verted th e in form ation con tain ed in you r CRC The revised class
m od el in to an in itial UML class m od el, you are th en read y to con tin u e diagram
flesh in g ou t you r m od el with ad d ed d etail. Class m od els con tain a
wealth of in form ation an d can be u sed for both th e an alysis an d d esign
of system s. To create an d evolve a class m od el, you n eed to m od el:
• Classes
• Meth od s
• Attribu tes
• Association s
• Dep en d en cies
• In h eritan ce relation sh ip s
• Aggregation association s
• Association classes
TIP Use the terminology of your users in all your models. The purpose of
analysis is to understand the world of your users, not to foist your
Use t he Term inology of artificial, technical terms on them. Remember, they’re the experts,
Your Users not you. In short, avoid geek-speak.
Ch a pter 6 • Determ in in g Wh a t to Bu ild: Object-Orien ted An a lysis 215
0..* offering of 1
Seminar Course
seminarNumber name
waitingList courseNumber
fees
addStudent(student) getFullName() Figure 6-13.
dropStudent(student) Normalizing the
“ Seminar” class
216 The Object Prim er
getFullName()
getCourseNumber()
setCourseNumber(number)
getFees()
setFees(amount)
getName()
setName(name)
Figu re 6 -15 p resen ts th e class d iagram th at resu lts3 wh en Figu res 6 -11,
6 -12, an d 6 -13 are com bin ed . Notice h ow “Professor””n ow referen ces th e
“Ad d ress” class, takin g ad van tage of th e work we d id to im p rove th e
“Stu d en t” class.
3
I h ave ch eated a little an d ad d ed th e m eth od “p u rch aseParkin gPass()” to th e “Profes-
sor” an d “Stu d en t” classes, even th ou gh I d id n ’t h ave req u irem en ts for th is. You ’ll see
wh y I ad d ed th is m eth od later in Section 6.3.4 wh en I d iscu ss in h eritan ce.
EnrollmentRecord
1 enrolled in 1..* 1..* enrolled in 1 0..* offering of 1
Student marksReceived Seminar Course
getAverageToDate() seminarNumber name
name
getFinalMark() waitingList courseNumber
phoneNumber
fees
emailAddress {ordered, FIFO}
studentNumber 0..* on waiting list 0..* addStudent(student) getFullName()
averageMark dropStudent(student)
0..*
isEligible (name,
studentNumber) 0..1
Address Professor instructs
getSeminarsTaken() lives
purchaseParkingPass() street
at name
city lives at phoneNumber
state
1 1 0..1 emailAddress 0..1
postalCode
salary
country
getInformation()
validate()
outputAsLabel() purchaseParkingPass()
Figure 6-15.
Combined class
diagram
218 The Object Prim er
D EFIN ITION S
Cla ss norm a liza t ion. The process by which you refactor the behavior within
a class diagram in such a way as to increase the cohesion of classes while mini-
mizing the coupling between them.
Cohesion. The degree of relatedness within an encapsulated unit (such as a
component or a class).
Coup ling. The degree of dependence between two items. In general, it is bet-
ter to reduce coupling wherever possible.
Get t er. A method to obtain the value of a data attribute, or to calculate the
value, of an object or class.
Set t er. A method that sets the value of a data attribute of an object or class.
Also known as a mutator.
TIP For each class involved in an association, there is always a multiplicity for it.
When the multiplicity is one and one only (for example, one and one only
Alwa ys Ind ica t e person may be President of the United States at any given time), then it is
t he Mult ip licit y common practice not to indicate the multiplicity and, instead, to assume it is
“ 1.” I believe this is a mistake. If the multiplicity is “ 1,” then indicate it as such.
When something is left off a diagram, I can’t tell if that is what is meant or if the
modeler simply hasn’t gotten around to working on that aspect of the model
yet. I always assume the modeler hasn’t done the work yet.
Ch a pter 6 • Determ in in g Wh a t to Bu ild: Object-Orien ted An a lysis 219
Professor Seminar
0..1 0..*
name seminarNumber
assistant
associate phoneNumber waitingList
0..* emailAddress {NAND}
salary addStudent(student)
0..1 0..* dropStudent(student)
getInformation()
instructor
0..1 advisor
mentors
6.3.4 Int rod ucing Reuse Bet ween Cla sses via Inherit a nce
Sim ilarities often exist between differen t classes. Very often two or m ore
classes will sh are th e sam e attributes an d/or th e sam e m eth ods. Because you
D EFIN ITION S
Ca rd ina lit y. Represents the concept “ how many?” in associations.
Op t iona lit y. Represents the concept “ do you need to have it?” in associations.
Mult ip licit y. The UML combines the concepts of cardinality and optionality
into the single concept of multiplicity.
Recursive a ssocia t ion. An association in which the objects involved in it are
instances of the same class. For example, people marry people.
Ch a pter 6 • Determ in in g Wh a t to Bu ild: Object-Orien ted An a lysis 221
Figure 6-17.
EnrollInSeminar Modeling
Seminar
<<UI>> dependencies
between classes
don ’t wan t to h ave to write th e sam e code repeatedly, you wan t a m ech an ism
th at takes advan tage of th ese sim ilarities. In h eritan ce is th at m ech an ism . In h eri-
tan ce m odels “is a” an d “is like” relation sh ips, en ablin g you to reu se existin g
data an d code easily. W h en A in h erits from B, we say A is th e su bclass of B
an d B is th e su p erclass of A. Fu rth erm ore, we say we h ave “p u re in h eri-
tan ce” wh en A in h erits all th e attribu tes an d m eth ods of B. Th e UML
m odelin g n otation for in h eritan ce is a lin e with a closed arrowh ead p oin t-
in g from th e su bclass to th e su p erclass.
In Figu re 6 -15, m an y sim ilarities occu r between th e “Stu den t” an d
“Professor” classes. Not on ly do th ey h ave sim ilar attribu tes, bu t th ey also
h ave sim ilar m eth ods. To take advan tage of th ese sim ilarities, I created a
n ew class called “Person ” an d h ad both “Stu den t” an d “Professor” in h erit
from it, as you see in Figu re 6 -18. Th is stru ctu re wou ld be called th e “Per-
son ” in h eritan ce h ierarch y becau se “Person ” is its root class. Th e “Person ”
class is abstract: Objects are n ot created directly from it, an d it cap tu res
th e sim ilarities between th e stu den ts an d p rofessors. Abstract classes are
m odeled with th eir n am es in italics, as op p osed to con crete classes, classes
from wh ich objects are in stan tiated, wh ose n am es are in n orm al text.
Both classes h ad a n am e, em ail address, an d p h on e n u m ber, so th ese
attribu tes were m oved in to “Person .” Th e “p u rch aseParkin gPass()”
m eth od was also com m on between th e two classes, so th at was also
m oved in to p aren t class. By in trodu cin g th is in h eritan ce relation sh ip to
th e m odel, I redu ced th e am ou n t of work to be p erform ed. In stead of
im p lem en tin g th ese resp on sibilities twice, th ey are im p lem en ted on ce, in
th e “Person ” class, an d reu sed by “Stu den t” an d “Professor.”
An in terestin g asp ect of Figu re 6 -18 is th e association between “Per- Associa t ions a re
son ” an d “Ad d ress.” First, th is association was p u sh ed u p to “Person ” inherit ed .
becau se both “Professor” an d “Stu d en t” h ad a “lives at” association with
D EFIN ITION S
Dep end ency rela t ionship . A dependency relationship exists between Class A
and B when instances of Class A interact with instances of Class B. Dependency
relationships are used when no direct relationship (inheritance, aggregation, or
association) exists between the two classes.
Persist ence. The issue of how objects are permanently stored.
222 The Object Prim er
D EFIN ITION S
Abst ra ct cla ss. A class that doesn’t have objects instantiated from it.
Concret e cla ss. A class that has objects instantiated from it.
Inherit a nce hiera rchy. A set of classes related through inheritance. Also
referred to as a class hierarchy.
Inherit a nce. The representation of an is a, is like, or is kind of relationship
between two classes. Inheritance promotes reuse by enabling a subclass to ben-
efit automatically from all the behavior it inherits from its superclass(es).
Root cla ss. The top-most class in an inheritance hierarchy.
Subcla ss. If Class B inherits from Class A, we say B is a subclass of A.
Sup ercla ss. If Class B inherits from Class A, we say A is a superclass of B.
Person Address
name street
phoneNumber city
0..1 lives at 1
emailAddress state
postalCode
purchaseParkingPass() country
validate()
outputAsLabel()
Student Professor
Figure 6-18.
studentNumber salary
Applying the
averageMark getInformation() concept of
inheritance in a
isEligible (name, class diagram
studentNumber)
getSeminarsTaken()
association s. In Figure 6-19, you see a sim ple class m odel depictin g th e rela-
tion sh ips between “Program ,” (a program is a collection of courses th at lead
to a degree) an d th e “Course” class. A course m ay be part of on e or m ore
program s—som e courses such as “ARC 305 Medieval Garden in g Tools” are
for gen eral in terest on ly an d are n ot part of a program —an d an y given pro-
gram h as on e or m ore courses in it. Also n otice h ow an association exists
between “Program ” an d “Course” represen tin g th at som e courses are rec-
om m en ded for a program , but are n ot officially offered as part of th em (m y
SMEs told m e th is). For exam ple, th e course “CSC 148 In troduction to
Com puter Scien ce” is recom m en ded for th e en gin eerin g, busin ess, an d
ph ysics program s with in th e un iversity. It m ade sen se to m odel th is rela-
tion sh ip with an association in stead of an aggregation because it isn ’t true
th at a recom m en ded course is part of a program .
In the class diagram of Figure 6-15, I was lucky because I used similar names for TIP
these attributes in both classes: “ name,” “ emailAddress,” and “ phoneNumber,”
respectively. However, you will often find situations where one class has an Som et im es
attribute called “ name,” whereas another one has “ firstName,” “ middleInitial,” Op p ort unit ies
and “ lastName.” You then need to decide whether these are, in fact, the same for Inherit a nce
thing and, if they are, be prepared to refactor your existing model, and perhaps Are Not So
even code to reflect whichever approach to storing a person’s name you accept. Obvious
A similar issue can also occur with methods and associations.
224 The Object Prim er
D EFIN ITION S
Aggrega t ion. The representation of “ is part of” associations.
Com p osit ion. A strong form of aggregation in which the “ whole” is com-
pletely responsible for its parts and each “ part” object is only associated with
the one “ whole” object.
Figure 6-19.
0..* 1..*
A course is part of a
program
Program 0..* recommended for 0..* Course
One of the following sentences should make sense: “ A subclass IS A superclass” TIP
or “ A subclass IS LIKE A superclass.” For example, it makes sense to say a
student is a person and a dragon is like a bird. It doesn’t make sense to say a Ap p ly t he
student is a vehicle or is like a vehicle, so the class “ Student” likely shouldn’t Sent ence Rule
inherit from “ Vehicle.”
EnrollmentRecord
marksReceived
getAverageToDate()
getFinalMark()
Figure 6-21.
Student 1..* 1..* Seminar An example of an
enrolled in associative class
226 The Object Prim er
D EFIN ITION S
Post cond it ion. An expression of the properties of the state of an operation or
use case after it has been invoked successfully.
Precond it ion. An expression of the constraints under which an operation or use
case will operate properly.
228 The Object Prim er
4
I su sp ect, in fu tu re version s of th e UML, we will see con d ition s d ocu m en ted u sin g th e
UML con strain t n otation d iscu ssed earlier.
230 The Object Prim er
Figure 6-22.
A UML activity
diagram for Enrolling in the
University for the
enrolling in school Fill out Enrollment [incorrect] Obtain Help to Fill first time
for the first time Forms Out Forms
AD #: 007
[correct]
Enroll in University
Attend University
Overview
Presentation
[accepted]
[rejected]
Make Initial Tuition
Enroll In Seminar(s)
Payment
D EFIN ITION S
Act ivit y d ia gra m . A UML diagram used to model high-level business
processes or the transitions between states of a class (in this respect, activity dia-
grams are effectively specializations of state chart diagrams).
Da t a -flow d ia gra m (DFD). A diagram that shows the movement of data
within a system among processes, entities, and data stores. Data-flow diagrams,
also called process diagrams, were a primary artifact of structured/procedural
modeling.
Flow cha rt . A diagram depicting the logic flow of a single process or method.
Flow charts were a primary artifact of structured/procedural modeling.
St a t e cha rt d ia gra m . A UML diagram that describes the states an object may
be in, as well as the transitions between states. Formerly referred to as a “ state
diagram” or “ state-transition diagram.”
TIP Every activity has at least one entry transition—otherwise, you would never
perform the activity, and at least one exit transition—otherwise you would
Act ivit ies Ha ve never stop performing it. For each activity, I always ask myself: From where
Ent ry a nd Exit could I get into this and where can I go from here? By asking this question, it
Tra nsit ions enables you to model the pertinent logic thoroughly.
Figure 6-23.
The iterative steps
of prototyping
Determine Needs
Build Prototype
Evaluate Prototype
[continue]
[finished]
TIP Although UI prototyping is an important part of analysis and design, it’s not
sufficient by itself. UI prototypes depict what will be built, but are unable to
User Int erfa ce communicate adequately how they will be used (that is what use case models
Prot ot yp ing Is are good for). Furthermore, UI prototypes don’t provide much indication as to
Not a Subst it ut e the details of the business logic behind the screens, which is what sequence and
for Ana lysis a nd activity diagrams are good at. And they aren’t good at depicting the static
Design structure of your software, which is where class models excel.
D EFIN ITION S
W YSIW YG. What You See Is What You Get.
W YSIW YN. What You See Is What You Need.
236 The Object Prim er
Figure 6-24.
The Business Entity
analysis pattern
EntityRole
BusinessEntity 1 1..* start
end
D EFIN ITION S
Inva ria nt . A set of assertions about an instance or class that must be true at all
“ stable” times, where a stable time is the period before a method is invoked on
the object/class and immediately after a method is invoked.
Object Const ra int La ngua ge (OCL). A formal language, similar to struc-
tured English, to express side-effect-free constraints within UML models.
TIP The real value of analysis patterns is the thinking behind them. A
pattern might not be the total solution to your problem, but it
How t o Use Ana lysis might provide enough insight to help save you several hours or
Pa t t erns Effect ively days during development. Consider analysis patterns as a good start
at solutions.
ContactPointType
ContactPoint
1 contacted through 1..* 0..* describes 1..* name
BusinessEntity
{ordered} sendTo() description
asLabel()
Phone
ShippingAddress 0..*
number
call()
sendTo()
asLabel()
ElectronicAddress SurfaceAddress
email street 1 Country
city 0..* name
sendTo() state phoneCode
asLabel() postalCode
sendTo()
asLabel()
Figure 6-25.
con sisten t m an n er, it’s th at m u ch easier to d o tech n ical walk- The Contact Point
th rou gh s th at en able you to im p rove th e q u ality of you r d evel- analysis pattern
op m en t efforts.
4. Pattern s are po ten tially better th an reusable co de. Peop le can
talk abou t reu sable cod e all th ey wan t, bu t th e d ifferen ces
between system p latform s m akes th is d ream d ifficu lt at best.
However, p attern s su p p ort th e reu se of oth er p eop le’s ap p roach es
to solvin g p roblem s (Am bler, 1998b; Am bler, 1999) an d , th ere-
fore, can be ap p lied in a wid e ran ge of en viron m en ts becau se
th ey are n ot en viron m en t-sp ecific.
5. More an d m ore pattern s are bein g developed every day. A lot of
excitin g work is goin g on in pattern s, with n ew pattern s bein g
in troduced every day. Th is en ables you to take advan tage of th e
developm en t efforts of th ousan ds of people, often for th e m ere cost
of a book, m agazin e, or teleph on e call to lin k you to th e In tern et.
m an u al does n ot fit all. He su ggests a tu torial m an u al for n ovice u sers, a The user
u ser m an u al for in term ediate u sers, an d a referen ce m an u al for exp ert d ocum ent a t ion
for your application
u sers. Tou rn iaire an d Farrell (1997) also recom m en d th at you develop a
includ es a t ut oria l
su p p ort u ser’s gu ide describin g th e su p p ort services p rovided to you r u ser
m anual, a reference
com m u n ity, a docu m en t th at is typ ically less th an a p age in len gth . m a nua l, a user
W h en ap p rop riate, you r u ser docu m en tation sh ou ld in clu de a descrip - m a nua l, a nd a
tion of th e skills n eeded to u se you r system . For exam p le, you r u sers m ay sup p ort user’s
req u ire train in g in you r bu sin ess dom ain or in basic com p u ter skills, su ch guid e.
as u sin g a m ou se. Th is in form ation is n eeded to develop train in g p lan s for
u sers an d by su p p ort en gin eers wh en th ey are attem p tin g to determ in e
th e sou rce of a p roblem . Qu ite often , su p p ort en gin eers will receive su p -
p ort calls wh ere th e solu tion is to give th e u ser addition al train in g.
D EFIN ITION S
Reference m a nua l. A document, either paper or electronic, aimed at experts
who need quick access to information.
Sup p ort user’s guid e. A brief document, usually a single page, that describes
the support services for your application that are available to your user commu-
nity. This guide includes support phone numbers, fax numbers, and Web site
locations, as well as hours of operations and tips for obtaining the best services.
Tut oria l. A document, either paper or electronic, aimed at novice users who
need to learn the fundamentals of an application.
User m a nua l. A document, either paper or electronic, aimed at intermediate
users who understand the basics of an application, but who may not know how
to perform all applicable work tasks with the application.
244 The Object Prim er
processes, processes you sh ould h ave docum en ted th e logic for usin g a
UML activity diagram . For large system s, you m ay fin d you h ave a section
for each UML package with in your use case m odel or even a separate user
m an ual. Th en , for each use case, add an appropriate subsection describin g
it; th e use case text will drive th e body of th at section . You will likely wan t
to com bin e steps in to paragraph s to m ake your docum en tation m ore read-
able. Wh erever you referen ce a UI elem en t, you m ay decide to in clude a
relevan t picture of th at portion of your user in terface (m y suggestion is to
wait un til you h ave baselin ed your user in terface design before in vestin g
th e tim e to gen erate th e pictures). You m ay also decide to replace refer-
en ces to busin ess rules with th eir description s to h elp in crease your user’s
un derstan din g of h ow th e system actually works. Alth ough m an y in th e
in dustry call th is a use case driven approach to writin g user docum en ta-
tion , it really is a m odel-driven approach because your use cases sim ply
aren ’t sufficien t for th is purpose.
Your use ca ses, Tu torials are d evelop ed in a sim ilar m an n er to u ser m an u als, alth ou gh
a ct ivit y d ia gra m s, a few d ifferen ces exist. First, tu torials focu s on th e m ost critical u ses of
a nd UI p rot ot yp e th e system , wh ereas a u ser m an u al sh ou ld focu s on th e en tire system .
d rive t he d evelop -
Secon d , tu torials sh ou ld h ave a m ore exp licit focu s on learn in g a p rod -
m ent of your user
m a nua l a nd
u ct, so th ey’ll in clu d e m ore d etailed u se in stru ction s th an a u ser m an u al
t ut oria l. m igh t. Th e assu m p tion is th at an yon e u sin g a tu torial likely kn ows little
abou t th e system an d , th erefore, n eed s m ore h elp , wh ereas som eon e
u sin g a u ser m an u al is p robably fam iliar with th e system itself, bu t n eed s
h elp with a sp ecific asp ect of it.
Your user int erfa ce You r referen ce m an u al, becau se it h as a sligh tly d ifferen t p u rp ose, is
m od el oft en d rives gen erally d riven by you r u ser in terface m od el, in stead of you r u se cases
t he d evelop m ent of an d activity d iagram s. I gen erally in clu d e an overview of th e system , sec-
your reference
tion s for each m ajor p ortion of you r system , an d su bsection s d escribin g
m a nua l.
th e m ajor u ser in terface elem en ts. Th e su bsection s sh ou ld d escribe th e
p u rp ose of th e relevan t screen / rep ort/ p age an d h ow to work with it.
You will often h ear advice with in th e software in dustry to write your
docum en tation before you write you code. Alth ough th is is a reason ably
TIP Writing is hard and writing good user documentation is even harder. It takes a
lot of effort and significant skill to do well, the type of skill technical writers
Hire a Technica l have. If possible, hire a technical writer to work with you to produce your user
W rit er documentation. This will improve the quality of your documentation and,
hence, the quality of your overall user interface, Hiring a technical writer will
also free you to focus on other development activities, such as modeling,
coding, and testing.
Ch a pter 6 • Determ in in g Wh a t to Bu ild: Object-Orien ted An a lysis 245
good practice, wh y do people give th is advice? I believe th e m otivation is Mod el before you
th at writin g user docum en tation first forces you to th in k about h ow your writ e your user
d ocum ent a t ion
system will be used before you start to build it. My advice is differen t:
a nd source cod e.
in vest th e tim e to un derstan d your system by developin g requirem en ts for
it, an alyzin g it, an d design in g it, an d th en let th is un derstan din g drive th e
developm en t of your source code an d your user docum en tation . I h ave
worked on several system s wh ere we developed th e user docum en tation in
parallel with th e source code, n ot before it, an d it worked out well.
Anything you put into a package should make sense when considered with the TIP
rest of the contents of the package. To determine whether a package is
cohesive, a good rule of thumb is you should be able to give your package a Pa cka ges
short, descriptive name. If you can’t, then you may have put several unrelated Should Be
things into the package. Cohesive
246 The Object Prim er
D EFIN ITION S
Cohesion. The degree of relatedness within an encapsulated unit (such as a
component or a class).
Pa cka ge. A UML construct that enables you to organize model elements into
groups.
Ch a pter 6 • Determ in in g Wh a t to Bu ild: Object-Orien ted An a lysis 247
D EFIN ITION
Ba seline. A tested and certified version of a deliverable representing a concep-
tual milestone, which, thereafter, serves as the basis for further development
and that can be modified only through formal change control procedures. A
particular version becomes a baseline when a responsible group decides to des-
ignate it as such.
248 The Object Prim er