01.067232640X.FM.qxd 2/20/04 10:28 AM Page i Teach Yourself UML 24 in Hours Joseph Schmuller THIRD EDITION 800 East 96th Street, Indianapolis, Indiana, 46240 USA 01.067232640X.FM.qxd 2/20/04 10:28 AM Page ii Sams Teach Yourself UML in 24 Hours,Third Edition Associate Publisher Michael Stephens Copyright © 2004 by Sams Publishing All rights reserved. No part of this book shall be reproduced, stored in a Acquisitions Editor retrieval system, or transmitted by any means, electronic, mechanical, Todd Green photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of Development Editor the information contained herein. Although every precaution has been Songlin Qiu taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for Managing Editor damages resulting from the use of the information contained herein. Charlotte Clapp International Standard Book Number: 0-672-32640-X Senior Project Editor Library of Congress Catalog Card Number: 2003098381 Matthew Purcell Printed in the United States of America Copy Editor First Printing: March 2004 Publication Services,Inc. 07 06 05 04 4 3 2 1 Indexer Trademarks Publication Services,Inc. All terms mentioned in this book that are known to be trademarks or Proofreader service marks have been appropriately capitalized. Sams Publishing Publication Services,Inc. 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 Technical Editor or service mark. Jeffrey Pajor Warning and Disclaimer Publishing Coordinator Every effort has been made to make this book as complete and as accu- Cindy Teeters 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 Multimedia Developer neither liability nor responsibility to any person or entity with respect to Dan Scherf any loss or damages arising from the information contained in this book or from the use of the CD or programs accompanying it. Interior Designer Gary Adair Bulk Sales Cover Designer Sams Publishing offers excellent discounts on this book when ordered in Alan Clements quantity for bulk purchases or special sales. For more information, please contact Page Layout U.S. Corporate and Government Sales Publication Services,Inc. 1-800-382-3419 Graphics [email protected] Laura Robbins For sales outside of the U.S., please contact International Sales 1-317-428-3341 [email protected] 01.067232640X.FM.qxd 2/20/04 10:28 AM Page iii 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 iv 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 v 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 vi vi Sams Teach Yourself UML in 24 Hours 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 01.067232640X.FM.qxd 2/20/04 10:28 AM Page vii 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 viii 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 ix 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 x 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
Description: