cis110 computer programming design chapter (13)
TRANSCRIPT
Programming Logic and DesignEighth Edition
Chapter 13System Modeling with the UML
Objectives
2
In this chapter, you will learn about:• System modeling• The Unified Modeling Language (UML)• UML use case diagrams• UML class and object diagrams• Other UML diagrams• Deciding when to use the UML and which UML
diagrams to use
Programming Logic and Design, Eighth Edition
Understanding System Modeling
3
• Most computer programs are part of a larger system– Each program is related to others– Produce input or output– Require careful planning
• System design– Detailed specification of how all parts of a system are
implemented and coordinated
Programming Logic and Design, Eighth Edition
Understanding System Modeling (continued)
4
• Basic principles:– Large systems are easier to understand when you break
them down into subsystems– Good modeling techniques are increasingly important as
the size and complexity of systems increase– Good models promote communication among technical
and nontechnical workers while ensuring professional and efficient business solutions
Programming Logic and Design, Eighth Edition
5
Understanding System Modeling (continued)
• The Unified Modeling Language (UML) allows you to:– Envision systems with an object-oriented perspective– Break a system into subsystems– Focus on the big picture– Hide the implementation detail– Communicate between programmers and businesspeople
about system design– Divide responsibilities for large systems
Programming Logic and Design, Eighth Edition
6
What Is the UML?
• A standard way to specify, construct, and document systems that use object-oriented methods
• A modeling language, not a programming language• Has its own notation – Consists of a set of specialized shapes and conventions
• Construct different kinds of software diagrams and model different kinds of systems
Programming Logic and Design, Eighth Edition
7
What Is the UML? (continued)
• Create top-view diagrams of business processes• Hide details and focus on functionality• Start with a generic view of an application– Introduce details and complexity later
• Useful as you begin designing business systems• Very large– Documentation is more than 800 pages– 14 diagram types allowing you to “see” the business
process from a different angle
Programming Logic and Design, Eighth Edition
8
What Is the UML? (continued)
• Structure diagrams – Emphasize the “things” in a system and include:
• Class diagrams• Object diagrams• Component diagrams• Composite structure diagrams• Package diagrams• Deployment diagrams• Profile diagrams
Programming Logic and Design, Eighth Edition
9
What Is the UML? (continued)
• Behavior diagrams – Emphasize what happens in a system and include:
• Use case diagrams• Activity diagrams• State machine diagrams
• Interaction diagrams – Emphasize the flow of control and data, and include:
• Sequence diagrams• Communication diagrams• Timing diagrams• Interaction overview diagrams
Programming Logic and Design, Eighth Edition
Using UML Use Case Diagrams
10
• Use case diagrams show how a business works – From the perspective of those who actually interact with
the business (employees, customers, suppliers, etc.)• Users are called actors– Represented by stick figures
• Use cases– Represented by ovals– System functions or services that are visible to the
system’s actors
Programming Logic and Design, Eighth Edition
Using UML Use Case Diagrams (continued)
11
Figure 13-1 Use case diagram for librarian
Programming Logic and Design, Eighth Edition
Using UML Use Case Diagrams (continued)
12
• Establishing use cases usually follows from analyzing the main events in a system
• Two main events from a librarian’s point of view:– acquireNewBook()– checkOutBook()
• Variations in use cases:– Extend– Include– Generalization
Programming Logic and Design, Eighth Edition
Using UML Use Case Diagrams (continued)
13
• Extend variation – Shows functions beyond those found in a base case– Scenario
• A variation in the sequence of actions required in a use case– Use case has at least one main scenario
• Stereotype– Can add <<extend>> near the line that shows a
relationship extension
Programming Logic and Design, Eighth Edition
Using UML Use Case Diagrams (continued)
14
Figure 13-2 Use case diagram for librarian with scenario extension
Figure 13-3 Use case diagram for librarian using stereotype
Programming Logic and Design, Eighth Edition
15
Using UML Use Case Diagrams (continued)
• Include variation – Case can be part of multiple use cases– Like subroutine or submodule– Include use case in an oval with a dashed arrow pointing
to the subroutine use case
Figure 13-4 Use case diagram for librarian using include relationship
Programming Logic and Design, Eighth Edition
Using UML Use Case Diagrams (continued)
• Generalization variation – Use case is less specific
than others– Substitute the more
specific case for a general one
– More specific scenarios are attached to the general scenario with open-headed dashed arrows
16
Figure 13-5 Use case diagram for librarian with generalizations
Programming Logic and Design, Eighth Edition
Using UML Use Case Diagrams (continued)
17
Figure 13-6 Use case diagram for librarian with multiple actors
Programming Logic and Design, Eighth Edition
Using UML Use Case Diagrams (continued)
18
• The use case diagram is only a tool to aid communication
• There is no single “correct” use case diagram• Elided– Omit parts of diagrams for clarity
Programming Logic and Design, Eighth Edition
Using UML Use Case Diagrams (continued)
19
Figure 13-7 Use case diagram emphasizing actors
Figure 13-8 Use case diagram emphasizing system requirements
Programming Logic and Design, Eighth Edition
Using UML Class and Object Diagrams
20
• Class diagram – Illustrates the names, attributes, and methods of a class – More useful to a system’s programmers than to its users
because it closely resembles code the programmers will write
• Rectangle divided into three sections:– Top section contains the name of the class– Middle section contains the names of the attributes – Bottom section contains the names of the methods
Programming Logic and Design, Eighth Edition
Using UML Class and Object Diagrams (continued)
21
Figure 13-9 Book class diagram
Programming Logic and Design, Eighth Edition
Using UML Class and Object Diagrams (continued)
• Use generalizations with class diagrams – Open-headed arrow– Show more general (or parent)
classes and more specific (or child) classes
– Child classes contain all the attributes of their parents
• Overriding– The mechanism by which a child class method is used by
default when a parent class contains a method with the same signature
22
Figure 13-10 LibraryItem class diagram showing generalization
Programming Logic and Design, Eighth Edition
Using UML Class and Object Diagrams (continued)
23
• Relationships between objects– Association relationship
• Describes the connection or link between objects• Represented by a straight line• Arithmetical relationship or ratio included (called cardinality or
multiplicity)– Whole-part relationship
• One or more classes make up the parts of a larger whole class• Also called an aggregation or a has-a relationship• Represented using an open diamond
Programming Logic and Design, Eighth Edition
Using UML Class and Object Diagrams (continued)
24
Figure 13-11 Class diagram with association relationship
Figure 13-12 Class diagram with several association relationships
Programming Logic and Design, Eighth Edition
Using UML Class and Object Diagrams (continued)
25
Figure 13-13 Class diagram with whole-part relationship
Figure 13-14 Object diagram for Library
• Object diagrams – Similar to class
diagrams– Model specific
instances of classes– Show a snapshot of
an object at one point in time
Programming Logic and Design, Eighth Edition
Using Other UML Diagrams
26
• Sequence diagram– Shows the timing of events in a single use case– Makes it easier to see the order in which activities occur– Horizontal axis (x-axis)
• Represents objects– Vertical axis (y-axis)
• Represents time
Programming Logic and Design, Eighth Edition
Using Other UML Diagrams (continued)
27
• Create sequence diagram– Place objects across the top of the diagram along the x-axis– Start at the left with the object or actor that begins the
action– Beneath each object, place a vertical dashed line
• Represents the period of time the object exists– Use horizontal arrows to show how the objects
communicate with each other over time
Programming Logic and Design, Eighth Edition
28
Figure 13-15 Sequence diagram for checking out a Book for a Patron
Using Other UML Diagrams (continued)
Programming Logic and Design, Eighth Edition
• Communication diagram – Emphasizes the
organization of objects in a system
– Similar to a sequence diagram but contains numbers to represent the precise order in which activities occur
– Focuses on object roles
29
Figure 13-16 Communication diagramfor checking out a Book for a Patron
Using Other UML Diagrams (continued)
Programming Logic and Design, Eighth Edition
30
• State machine diagram– Shows the different statuses
of a class or an object at different points in time
• Rounded rectangles– Represent each state
• Arrows – Show sequence
• Solid dot– Start and stop states Figure 13-17 State machine diagram
for states of a Book
Using Other UML Diagrams (continued)
Programming Logic and Design, Eighth Edition
31
• Activity diagram– Shows the flow of actions of a system
• Symbols – Flowchart stop and start symbols– Diamonds describe decisions– Fork
• Defines a branch in which all paths are followed simultaneously– Join
• Reunites the flow of control after a fork
Using Other UML Diagrams (continued)
Programming Logic and Design, Eighth Edition
32
• Time signal– Indicates that a specific amount of time should pass
before an action starts– Looks like two
stacked triangles
Figure 13-20 A time signal starting an action
Using Other UML Diagrams (continued)
Programming Logic and Design, Eighth Edition
• Component and deployment diagrams– Document physical aspects of
systems– Component diagram
• Emphasizes the files, database tables, documents, and other components
– Deployment diagram• Focuses on a system’s hardware
33
Figure 13-21 Component diagram
Using Other UML Diagrams (continued)
Programming Logic and Design, Eighth Edition
34
Figure 13-21 Component diagram Figure 13-22 Deployment diagram
Using Other UML Diagrams (continued)
Programming Logic and Design, Eighth Edition
35
Using Other UML Diagrams (continued)
• Profile diagram – A newer type of UML diagram– Extends a UML model:
• For a particular domain – Like for financial or healthcare applications
• For a particular platform– Like for .NET or Java
Programming Logic and Design, Eighth Edition
36
Diagramming Exception Handling
• Exception handling – The set of the object-oriented techniques used to handle
program errors• Protected node– try block in the UML
• Handler body node– catch block in the UML
Programming Logic and Design, Eighth Edition
37
Diagramming Exception Handling (continued)
Figure 13-23 Exceptions in the Book check-out activity
Programming Logic and Design, Eighth Edition
38
Deciding When to Use the UMLand Which UML Diagrams to Use
• Criticisms:– Size – too large and complex– Imprecision – combination of rules and English– Complexity – difficult to learn
• Under the right circumstances, the UML can increase communication
• Users, managers, designers, and technicians each prefer specific system views
• Very few systems require diagrams of all UML types
Programming Logic and Design, Eighth Edition
Summary
39
• System design: a detailed specification of how all parts of a system are implemented and coordinated
• UML (Unified Modeling Language)– A standard modeling language for object-oriented systems– Has its own notation– 14 diagram types
• Use case– Shows how a business works from the perspective of those who
interact with the business– Includes actors– Variations: extend relationships, include relationships,
generalizationsProgramming Logic and Design, Eighth Edition
Summary (continued)
40
• Class diagram– Illustrates names, attributes, and methods of a class– Contains the name of the class, the names of the
attributes, and the names of the methods– Can show generalizations and relationships between
objects– Object diagrams model specific instances of classes at
one point in time
Programming Logic and Design, Eighth Edition
Summary (continued)
41
• Sequence diagram– Shows timing of events
• Communication diagram– Emphasizes organization of objects in a system
• State machine– Shows different statuses of a class or an object at
different points in time• Activity diagram– Shows the flow of actions, including decision branches
Programming Logic and Design, Eighth Edition
Summary (continued)
42
• Component diagram– Emphasizes files, database tables, documents used by a
system’s software• Deployment diagram– Focuses on a system’s hardware
• Profile diagram– Extends the UML for a particular domain or platform
• Each UML diagram provides a different view of a system
Programming Logic and Design, Eighth Edition