Tải bản đầy đủ (.pdf) (51 trang)

Teach Yourself UML in 24 Hours 3rd phần 1 doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (490.65 KB, 51 trang )

800 East 96th Street, Indianapolis, Indiana, 46240 USA
Teach Yourself
in
24
Hours
Joseph Schmuller
UML
THIRD EDITION
01.067232640X.FM.qxd 2/20/04 10:28 AM Page i
Sams Teach Yourself UML in 24 Hours, Third Edition
Copyright © 2004 by Sams Publishing
All rights reserved. No part of this book shall be reproduced, stored in a
retrieval system, or transmitted by any means, electronic, mechanical,
photocopying, recording, or otherwise, without written permission from
the publisher. No patent liability is assumed with respect to the use of
the information contained herein. Although every precaution has been
taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions. Nor is any liability assumed for
damages resulting from the use of the information contained herein.
International Standard Book Number: 0-672-32640-X
Library of Congress Catalog Card Number: 2003098381
Printed in the United States of America
First Printing: March 2004
07 06 05 04 4321
Trademarks
All terms mentioned in this book that are known to be trademarks or
service marks have been appropriately capitalized. Sams Publishing
cannot attest to the accuracy of this information. Use of a term in this
book should not be regarded as affecting the validity of any trademark
or service mark.
Warning and Disclaimer


Every effort has been made to make this book as complete and as accu-
rate as possible, but no warranty or fitness is implied. The information
provided is on an “as is” basis. The author and the publisher shall have
neither liability nor responsibility to any person or entity with respect to
any loss or damages arising from the information contained in this
book or from the use of the CD or programs accompanying it.
Bulk Sales
Sams Publishing offers excellent discounts on this book when ordered in
quantity for bulk purchases or special sales. For more information,
please contact
U.S. Corporate and Government Sales
1-800-382-3419

For sales outside of the U.S., please contact
International Sales
1-317-428-3341

Associate Publisher
Michael Stephens
Acquisitions Editor
Todd Green
Development Editor
Songlin Qiu
Managing Editor
Charlotte Clapp
Senior Project Editor
Matthew Purcell
Copy Editor
Publication Services, Inc.
Indexer

Publication Services, Inc.
Proofreader
Publication Services, Inc.
Technical Editor
Jeffrey Pajor
Publishing Coordinator
Cindy Teeters
Multimedia Developer
Dan Scherf
Interior Designer
Gary Adair
Cover Designer
Alan Clements
Page Layout
Publication Services, Inc.
Graphics
Laura Robbins
01.067232640X.FM.qxd 2/20/04 10:28 AM Page ii
Contents at a Glance
Introduction 1
Part I Getting Started
HOUR 1 Introducing the UML 7
2 Understanding Object-Orientation 31
3 Working with Object-Orientation 47
4 Working with Relationships 61
5 Understanding Aggregations, Composites, Interfaces, and
Realizations 79
6 Introducing Use Cases 91
7 Working with Use Case Diagrams 103
8 Working with State Diagrams 123

9 Working with Sequence Diagrams 135
10 Working with Communication Diagrams 157
11 Working with Activity Diagrams 173
12 Working with Component Diagrams 197
13 Working with Deployment Diagrams 213
14 Understanding Packages and Foundations 225
15 Fitting the UML into a Development Process 249
Part II A Case Study
HOUR 16 Introducing the Case Study 267
17 Performing a Domain Analysis 285
18 Gathering System Requirements 307
19 Developing the Use Cases 325
20 Getting into Interactions 339
21 Designing Look, Feel, and Deployment 351
22 Understanding Design Patterns 367
01.067232640X.FM.qxd 2/20/04 10:28 AM Page iii
Part III Looking Ahead
HOUR 23 Modeling Embedded Systems 383
24 Shaping the Future of the UML 403
Part IV Appendices
A Quiz Answers 421
B Working with a UML Modeling Tool 435
C A Summary in Pictures 457
Index 467
01.067232640X.FM.qxd 2/20/04 10:28 AM Page iv
Table of Contents
Introduction 1
What’s New in This Edition 1
Who Should Read This Book? 2
Organization of This Book 2

Conventions Used Throughout This Book 3
Part I Getting Started 5
HOUR 1: Introducing the UML 7
Adding a Method to the Madness 8
How the UML Came to Be 9
Components of the UML 10
Class Diagram 11
Object Diagram 12
Use Case Diagram 13
State Diagram 13
Sequence Diagram 14
Activity Diagram 16
Communication Diagram 16
Component Diagram 18
Deployment Diagram 19
Some Other Features 20
Notes 20
Keywords and Stereotypes 20
New Diagrams in UML 2.0 22
Composite Structure Diagram 22
Interaction Overview Diagram 23
Timing Diagram 24
Something Old, Something New—The Package Diagram 25
01.067232640X.FM.qxd 2/20/04 10:28 AM Page v
Why So Many Diagrams? 26
But Isn’t It Just a Bunch of Pictures? 26
Summary 27
Q&A 28
Workshop 29
Quiz 29

Exercises 29
HOUR 2: Understanding Object-Orientation 31
Objects, Objects Everywhere 32
Some Object-Oriented Concepts 34
Abstraction 34
Inheritance 35
Polymorphism 36
Encapsulation 37
Message Sending 38
Associations 40
Aggregation 41
The Payoff 42
Summary 43
Q&A 45
Workshop 45
Quiz 45
HOUR 3: Working with Object-Orientation 47
Visualizing a Class 47
Attributes 48
Operations 50
Attributes, Operations, and Visualization 51
Responsibilities and Constraints 52
Attached Notes 54
Classes—What They Do and How to Find Them 54
Summary 57
vi
Sams Teach Yourself UML in 24 Hours
01.067232640X.FM.qxd 2/20/04 10:28 AM Page vi
Contents
vii

Q&A 58
Workshop 58
Quiz 58
Exercises 59
HOUR 4: Working with Relationships 61
Associations 61
Constraints on Associations 63
Association Classes 63
Links 64
Multiplicity 64
Qualified Associations 65
Reflexive Associations 67
Inheritance and Generalization 67
Discovering Inheritance 69
Abstract Classes 70
Dependencies 70
Class Diagrams and Object Diagrams 71
Summary 73
Q&A 75
Workshop 75
Quiz 76
Exercises 76
HOUR 5: Understanding Aggregations, Composites,
Interfaces, and Realizations 79
Aggregations 79
Constraints on Aggregations 80
Composites 81
Composite Structure Diagram 81
Interfaces and Realizations 82
Interfaces and Ports 86

Visibility 87
Scope 87
01.067232640X.FM.qxd 2/20/04 10:28 AM Page vii
viii
Sams Teach Yourself UML in 24 Hours
Summary
88
Q&A 89
Workshop 89
Quiz 89
Exercises 89
HOUR 6: Introducing Use Cases 91
Use Cases: What They Are
91
Use Cases: Why They’re Important 92
An Example: The Soda Machine 92
The “Buy Soda” Use Case 93
Additional Use Cases 94
Including a Use Case 96
Extending a Use Case 97
Starting a Use Case Analysis 98
Summary 98
Q&A 100
Workshop 100
Quiz 100
Exercises 101
HOUR 7: Working with Use Case Diagrams 103
Representing a Use Case Model
103
The Soda Machine Revisited

104
Tracking the Steps in the Scenarios 105
Visualizing Relationships Among Use Cases
106
Inclusion
106
Extension 107
Generalization
109
Grouping
110
Use Case Diagrams in the Analysis Process 110
Applying Use Case Models: An Example
111
Understanding the Domain
111
01.067232640X.FM.qxd 2/20/04 10:28 AM Page viii
Contents
ix
Understanding the Users 111
Understanding the Use Cases 113
Drilling Down 113
Taking Stock of Where We Are 115
Structural Elements 116
Relationships 116
Grouping
117
Annotation 117
Extension 117
. . . And More 117

The Big Picture 117
Summary 117
Q&A 120
Workshop 120
Quiz 120
Exercises 121
HOUR 8: Working with State Diagrams 123
What Is a State Diagram? 123
The Fundamental Symbol Set 124
Adding Details to the State Icon 124
Adding Details to the Transitions: Events and Actions 125
Adding Details to the Transitions: Guard Conditions
127
Substates
127
Sequential Substates 128
Concurrent Substates
128
History States
129
New in UML 2.0 130
Why Are State Diagrams Important? 131
Building the Big Picture 131
Summary 131
Q&A
133
01.067232640X.FM.qxd 2/20/04 10:28 AM Page ix
x
Sams Teach Yourself UML in 24 Hours
Workshop

133
Quiz 133
Exercises 134
HOUR 9: Working with Sequence Diagrams 135
What Is a Sequence Diagram? 135
Objects 136
Messages 136
Time 137
Cars and Car Keys 138
A Class Diagram 138
A Sequence Diagram 139
The Soda Machine 141
Sequence Diagrams: The Generic Sequence Diagram 144
Creating an Object in the Sequence 146
Framing a Sequence: Sequence Diagramming in UML 2.0 149
Interaction Occurrences 149
Combined Interaction Fragments 151
Building the Big Picture 153
Summary 153
Q&A 155
Workshop 155
Quiz 155
Exercises 156
HOUR 10: Working with Communication Diagrams 157
What Is a Communication Diagram? 158
Cars and Car Keys 159
Changing States and Nesting Messages 160
The Soda Machine 162
Creating an Object 163
One More Point About Numbering 164

01.067232640X.FM.qxd 2/20/04 10:28 AM Page x
Contents
xi
A Few More Concepts 164
Multiple Receiving Objects in a Class 165
Representing Returned Results 165
Active Objects 166
Synchronization 166
Building the Big Picture 168
Summary 168
Q&A 170
Workshop 170
Quiz 170
Exercises 171
HOUR 11: Working with Activity Diagrams 173
The Basics: What Is an Activity Diagram? 174
Decisions, Decisions, Decisions 174
Concurrent Paths 175
Signals 175
Applying Activity Diagrams 177
A Process: Creating a Document 177
Swimlanes 177
Hybrid Diagrams 180
New Concepts from UML 2.0 181
The Objects of an Activity 181
Taking Exception 183
Deconstructing an Activity
184
Marking Time and Finishing a Flow 186
Special Effects

187
An Overview of an Interaction
188
Building the Big Picture 191
Summary
191
Q&A
193
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xi
xii
Sams Teach Yourself UML in 24 Hours
Workshop
194
Quiz 194
Exercises 194
HOUR 12: Working with Component Diagrams 197
What Is (and What Isn’t) a Component? 197
Components and Interfaces 198
Reviewing Interfaces 198
Replacement and Reuse 199
What Is a Component Diagram? 200
Representing a Component in UML 1.x and UML 2.0 200
Representing Interfaces 201
Boxes—Black and White 202
Applying Component Diagrams 203
Component Diagrams in the Big Picture 209
Summary 209
Q&A 211
Workshop 211
Quiz 211

Exercises 211
HOUR 13: Working with Deployment Diagrams 213
What Is a Deployment Diagram? 213
Applying Deployment Diagrams 216
A Home System 216
A Token-Ring Network 216
ARCnet 218
Thin Ethernet 218
The Ricochet Wireless Network 219
Deployment Diagrams in the Big Picture 221
Summary 221
Q&A 223
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xii

xiv
Sams Teach Yourself UML in 24 Hours
HOUR 15: Fitting the UML into a Development Process 249
Methodologies: Old and New
250
The Old Way
250
A New Way 251
What a Development Process Must Do 251
GRAPPLE 253
RAD3: The Structure of GRAPPLE 254
Requirements Gathering
255
Analysis 257
Design 259
Development 260

Deployment 261
The GRAPPLE Wrap-up 261
Summary 262
Q&A 263
Workshop 263
Quiz 263
Part II A Case Study 265
HOUR 16: Introducing the Case Study 267
Getting Down to Business 267
GRAPPLEing with the Problem 268
Discovering Business Processes 268
Serving a Customer 269
Preparing the Meal 278
Cleaning the Table 279
Lessons Learned 281
Summary 282
Q&A 283
Workshop 283
Quiz 284
Exercises 284
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xiv
HOUR 17: Performing a Domain Analysis 285
Analyzing the Business Process Interview 286
Developing the Initial Class Diagram 287
Grouping the Classes 289
Forming Associations 290
Associations with Customer 291
Associations with Server 294
Associations with Chef
295

Associations with Busser 295
Associations with Manager 296
A Digression 297
Forming Aggregates and Composites 298
Filling Out the Classes 300
Customer 300
Employee 301
Check 302
General Issues About Models 303
Model Dictionary 303
Diagram Organization 303
Lessons Learned 303
Summary 304
Q&A 305
Workshop 305
Quiz 305
Exercises 305
HOUR 18: Gathering System Requirements 307
Developing the Vision 308
Setting Up for Requirements Gathering 316
The Requirements JAD Session 317
The Outcome 320
Now What? 323
Contents
xv
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xv
Summary 323
Q&A 324
Workshop 324
Quiz 324

Exercise 324
HOUR 19: Developing the Use Cases 325
The Care and Feeding of Use Cases 325
The Use Case Analysis 326
The Server Package 327
Take an Order 328
Transmit the Order to the Kitchen 329
Change an Order 330
Track Order Status 330
Notify Chef About Party Status 331
Total Up a Check 333
Print a Check 333
Summon an Assistant 334
Remaining Use Cases 336
Components of the System 336
Summary 337
Q&A 338
Workshop 338
Quiz 338
Exercises 338
HOUR 20: Getting into Interactions 339
The Working Parts of the System 339
The Server Package 339
The Chef Package 340
The Busser Package 341
The Assistant Server Package 341
The Assistant Chef Package 341
xvi
Sams Teach Yourself UML in 24 Hours
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xvi

The Bartender Package 341
The Coat-Check Clerk Package 342
Interactions in the System 342
Take an Order 343
Change an Order 344
Track Order Status 346
Implications 347
Summary 348
Q&A 349
Workshop 350
Quiz 350
Exercises 350
HOUR 21: Designing Look, Feel, and Deployment 351
Some General Principles of GUI Design 351
The GUI JAD Session 353
From Use Cases to User Interfaces 354
UML Diagrams for GUI Design 357
Mapping Out System Deployment 358
The Network 358
The Nodes and the Deployment Diagram 359
Next Steps 359
And Now a Word from Our Sponsor 361
Empowering a Sales Force 361
Expanding in the Restaurant World 362
Summary 363
Q&A 365
Workshop 366
Quiz 366
Exercises 366
Contents

xvii
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xvii
HOUR 22: Understanding Design Patterns 367
Parameterization 367
Design Patterns 370
Chain of Responsibility 371
Chain of Responsibility: Restaurant Domain 372
Chain of Responsibility: Web Browser Event Models 373
Your Own Design Patterns 374
The Advantages of Design Patterns
377
Summary 377
Q&A 379
Workshop 379
Quiz 379
Exercise 379
Part III Looking Ahead 381
HOUR 23: Modeling Embedded Systems 383
Back to the Restaurant 383
The Mother of Invention 384
Fleshing Out the GetAGrip 385
What Is an Embedded System? 387
Embedded Systems Concepts 388
Time 388
Threads 388
Interrupts 389
Operating System 390
Modeling the GetAGrip 393
Classes 393
Use Cases 394

Interactions 395
General State Changes 398
Deployment 398
xviii
Sams Teach Yourself UML in 24 Hours
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xviii
Flexing Their Muscles 399
Summary 400
Q&A 401
Workshop 401
Quiz 401
Exercises 401
HOUR 24: Shaping the Future of the UML 403
Extensions for Business 403
Lessons from the Business Extensions 405
Graphic User Interfaces 405
Connecting to Use Cases 405
Modeling the GUI 406
Expert Systems 408
Components of an Expert System 408
An Example 410
Modeling the Knowledge Base 411
Web Applications 414
That’s All, Folks 416
Summary 417
Q&A 418
Workshop 418
Quiz 418
Exercises 418
Part IV Appendixes 419

APPENDIX A Quiz Answers 421
Hour 1 421
Hour 2 421
Hour 3 422
Hour 4 422
Hour 5 423
Contents
xix
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xix
Hour 6 424
Hour 7 424
Hour 8 425
Hour 9 425
Hour 10 426
Hour 11 426
Hour 12 427
Hour 13 428
Hour 14 428
Hour 15 428
Hour 16 429
Hour 17 430
Hour 18 430
Hour 19 430
Hour 20 431
Hour 21 431
Hour 22 432
Hour 23 432
Hour 24 433
APPENDIX B Working with a UML Modeling Tool 435
What You Should Find in a Modeling Tool 435

Working with UML in Visio Professional Edition 436
Getting Started 438
The Class Diagram 438
The Object Diagram 448
The Sequence Diagram 451
A Few Words About a Few Tools 456
Rational Rose 456
Select Component Architect 456
Visual UML 456
xx
Sams Teach Yourself UML in 24 Hours
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xx
APPENDIX C A Summary in Pictures 457
Activity Diagram 457
Class Diagram 459
Communication Diagram 460
Component Diagram 461
Composite Structure Diagram 461
Deployment Diagram 462
Object Diagram 462
Package Diagram
463
Parameterized Collaboration
463
Sequence Diagram 464
State Diagram 465
Timing Diagram 465
Use Case Diagram 466
Index 467
Contents

xxi
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xxi
About the Author
Joseph Schmuller, a veteran of over 20 years in Information Technology, is a
Technical Architect with Blue Cross–Blue Shield of Florida. From 1991 through 1997,
he was Editor in Chief of PC AI Magazine. He has written numerous articles and
reviews on advanced computing technology and is the author of ActiveX No experi-
ence required and Dynamic HTML Master the Essentials. Holder of a Ph.D. from the
University of Wisconsin, he is an Adjunct Professor at the University of North
Florida.
Dedication
To my wonderful mother, Sara Riba Schmuller,
Who taught me how to teach myself.
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xxii
Acknowledgments
Writing a book is an arduous process, and creating a new edition is no day at the
beach, either. Happily, the world-class team at Sams Publishing has made it a lot eas-
ier on every occasion. It’s a pleasure once again to acknowledge their contributions.
For the first edition, Acquisitions Editor Chris Webb and Development Editor Matt
Purcell helped turn my thoughts into readable prose. Technical Editors Bill Rowe and
Michael Tobler made sure the content was technically sound. Senior Editor Susan
Moore and the outstanding artists and Production Staff turned the manuscript and
its numerous diagrams into production quality.
For the second edition, Associate Publisher Michael Stephens, Development Editor
Christy Franklin, Production Editor Matt Wynalda, and Technical Editor Paul
Gustavson did an exemplary job from start to finish.
In this edition, Acquisitions Editor Todd Green catalyzed the process. Todd and
Development Editor Songlin Qiu kept everything running smoothly. They also
showed the patience of saints, for which I’m most grateful. Project Editor Matt
Purcell (back for a return engagement in a new role) did an outstanding job on the

comprehensibility of the material, and Project Manager Jan Fisher was indispens-
able in keeping the book on track. Technical Editor Jeffrey Pajor supplied expertise
that significantly tightened up the content.
As always, my sincerest thanks to my agent, David Fugate of Waterside Productions.
During the writing of all the editions of this book, my professional colleagues have
provided empathy and cooperation. In particular, conversations with Keith Barrett
and Rob Warner helped clarify my thinking on a number of issues. Sadly, the time
of my involvement with the first edition marked the untimely passing of Tom
Williamson, the director of the division in which Keith, Rob, and I worked. Tom was
an advisor, mentor, colleague, and friend.
I thank my dearest friends, the Spragues of Madison, Wisconsin, for their continuing
support and friendship. I thank my mother and my brother David for their love and
for always being there for me, and Kathryn (LOML and GOMD) for always being
everything to me.
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xxiii
We Want to Hear from You
As the reader of this book, you are our most important critic and commentator. We
value your opinion and want to know what we’re doing right, what we could do bet-
ter, what areas you’d like to see us publish in, and any other words of wisdom you’re
willing to pass our way.
As an associate publisher for Sams Publishing, I welcome your comments. You can
e-mail or write me directly to let me know what you did or didn’t like about this
book—as well as what we can do to make our books better.
Please note that I cannot help you with technical problems related to the topic of this book.
We do have a User Services group, however, where I will forward specific technical questions
related to the book.
When you write, please be sure to include this book’s title and author as well as your
name, e-mail address, and phone number. I will carefully review your comments
and share them with the author and editors who worked on the book.
E-mail:

Mail: Michael Stephens
Associate Publisher
Sams Publishing
800 East 96th Street
Indianapolis, IN 46240 USA
For more information about this book or another Sams Publishing title, visit our
Web site at
www.samspublishing.com. Type the ISBN (excluding hyphens) or the title
of a book in the Search field to find the page you’re looking for.
01.067232640X.FM.qxd 2/20/04 10:28 AM Page xxiv
Introduction
It’s all about vision. A complex system comes into being when someone has a vision
of how technology can make things better. Developers have to fully understand the
vision and keep it firmly in mind as they create the system that realizes the vision.
System development projects are successful to the extent they bridge the gap
between visionary and developer. The Unified Modeling Language (UML) is a tool
for building the bridge. It helps you capture the vision for a system and then enables
you to communicate the vision to anyone who has a stake in the system. It does this
via a set of symbols and diagrams. Each diagram plays a different role within the
development process.
The goal of this book—for all three editions—is to give you a firm foundation in the
UML in 24 hours of study. Each hour presents examples to strengthen your under-
standing, and most of the hours provide exercises that enable you to put your new-
found knowledge to use.
What’s New in This Edition
In preparing this edition, I went through the first two and tightened up the prose,
adding and updating material where necessary. Some of the additions were neces-
sary because of UML 2.0, the newly adopted version. Others were necessitated by the
passage of time and the advancement of technology.
As in the first two editions, Hour 14, “Understanding Packages and Foundations,”

presents theoretical concepts at the foundation of the UML. In this edition, I’ve
expanded this hour considerably in order to accommodate new concepts from
UML 2.0.
I’ve refined some of the thinking behind the models and diagrams and added quiz
questions and exercises. As part of the refinement, in this edition I precede every
interaction diagram with a class diagram that shows the operations of the classes.
The goal is to clarify the messages that appear in the interaction diagrams and
make them more intuitive. If you know a little about the UML, you’ll understand
what I just said. If not . . . well, then . . . you won’t. By the end of the book, however,
I’m certain you will.
02.067232640X.Intro.qxd 2/20/04 10:44 AM Page 1

×