CS 501: Software Engineering Object Oriented Design II CS 501 Spring 2002

advertisement
CS 501: Software Engineering
Lecture 17
Object Oriented Design II
1
CS 501 Spring 2002
Administration
Design Presentations
Sign up with Rosemary Adessa
Quiz 3
On Thursday this week -- no alternatives
Final grades will be based on best 3 quizzes
2
CS 501 Spring 2002
The Waterfall Model
Requirements
Requirements Analysis
System design
Design
Program design
Implementation
Coding
Unit & Integration Testing
System Testing
Acceptance Testing
Operation & Maintenance
3
CS 501 Spring 2002
The Unified Modeling Language
UML is a standard language for modeling software systems
• Serves as a bridge between the requirements specification
and the implementation.
• Provides a means to specify and document the design of a
software system.
• Is process and programming language independent.
• Is particularly suited to object-oriented program
development.
4
CS 501 Spring 2002
Useful Texts
Grady Booch, James Rumbaugh, Ivar Jacobson, The Unified
Modeling Language. Addison-Wesley 1999.
Grady Booch, Object-Oriented Analysis and Design with
Applications, second edition. Benjamin/Cummings 1994.
Rob Pooley, Perdita Stevens, Using UML Software
Engineering with Objects and Components. Addison-Wesley
1999.
5
CS 501 Spring 2002
Rational Rose
Rational Rose is a system for creating and managing
UML diagrams.
It is available on all Computer Science Department
computers.
See: http://adm/Software/purify_install.htm for
installation instructions.
6
CS 501 Spring 2002
The Importance of Modeling
• A model is a simplification of reality.
• We build models so that we can better understand the
system we are developing.
• We build models of complex system because we cannot
comprehend such a system in its entirety.
Models can be informal or formal. The more complex the
project the more valuable a formal model becomes.
BRJ
7
CS 501 Spring 2002
Principles of Modeling
• The choice of what models to create has a profound
influence on how a problem is attacked and how a
solution is shaped.
• Every model can be expressed at different levels of
precision.
• The best models are connected to reality.
• No single model is sufficient. Every nontrivial
system is best approached through a small set of
nearly independent models.
BRJ
8
CS 501 Spring 2002
Modeling Classes
Given a real-life system, how do you decide what classes to use?
• What terms do the users and implementers use to describe the
system? They are candidates for classes.
• Is each candidate class crisply defined?
•
For each class, what is its set of responsibilities? Are the
responsibilities evenly balanced among the classes?
• What attributes and operations does each class need to carry
out its responsibilities?
9
CS 501 Spring 2002
Noun Identification: A Library Example
The library contains books and journals. It may have several
copies of a given book. Some of the books are reserved for
short-term loans only. All others may be borrowed by any
library member for three weeks. Members of the library can
normally borrow up to six items at a time, but members of
staff may borrow up to 12 items at one time. Only members
of staff may borrow journals.
The system must keep track of when books and journals are
borrowed and returned and enforce the rules.
10
CS 501 Spring 2002
Noun Identification: A Library Example
The library contains books and journals. It may have several
copies of a given book. Some of the books are reserved for
short-term loans only. All others may be borrowed by any
library member for three weeks. Members of the library can
normally borrow up to six items at a time, but members of
staff may borrow up to 12 items at one time. Only members
of staff may borrow journals.
The system must keep track of when books and journals are
borrowed and returned and enforce the rules.
11
CS 501 Spring 2002
Candidate Classes
Library
Book
Journal
Copy
ShortTermLoan
LibraryMember
Week
MemberOfLibrary
Item
Time
MemberOfStaff
System
Rule
12
the name of the system
event
measure
repeat
book or journal
abstract term
general term
general term
CS 501 Spring 2002
Relations between Classes
Book
Journal
Copy
LibraryMember
Item
MemberOfStaff
is an
is an
is a copy of a
Item
Item
Book
is a
LibraryMember
Is Item needed?
13
CS 501 Spring 2002
Operations
LibraryMember
borrows
Copy
LibraryMember
returns
Copy
MemberOfStaff
borrows
Journal
MemberOfStaff
returns
Journal
Item not needed yet.
14
CS 501 Spring 2002
Class Diagram
MemberOfStaff
LibraryMember
1
1
on loan
on loan
0..12
Journal
0..*
Copy
is a copy of
1..*
15
Book
1
CS 501 Spring 2002
Rough Sketch: Wholesale System
A wholesale merchant supplies retail stores from
stocks of goods in a warehouse.
What classes would you use to model this business?
16
CS 501 Spring 2002
Rough Sketch: Wholesale System
RetailStore
Order
Merchant
Product
Warehouse
Invoice
17
Shipment
CS 501 Spring 2002
Rough Sketch: Wholesale System
RetailStore
name
address
contactInfo
financialInfo
Merchant
Warehouse
Order
Product
Reversal
Invoice
18
Shipment
damaged()
return()
wrongItem()
Responsibilities
-track status of
shipped products
responsibility
(text field)
CS 501 Spring 2002
Expanding a Class:
Modeling Financial Information
RetailStore
association
1
* Transaction
Which class is
responsible for the
financial records for
a store?
19
Payment
Invoice
CS 501 Spring 2002
Modeling Invoice
Shipment
???
RetailStore
invoiceRecord
goodsShipped
Invoice
invoiceNumber
PartsList
adornments
+goodsShipped()
+ public
-sendInvoice()
- private
20
CS 501 Spring 2002
Lessons Learned
Design is empirical. There is no single correct design.
During the design process:
• Eliding: Elements are hidden to simplify the diagram
• Incomplete: Elements may be missing.
• Inconsistency: The model may not be consistent
The diagram is not the whole design. Diagrams must
be backed up with specifications.
21
CS 501 Spring 2002
Levels of Abstraction
The complexity of a model depends on its level of abstraction:
•
High-levels of abstraction show the overall system.
•
Low-levels of abstraction are needed for implementation.
Two approaches:
22
•
Model entire system at same level of abstraction, but present
diagrams with different levels of detail.
•
Model parts of system at different levels of abstraction.
CS 501 Spring 2002
Actor and Use Case Diagram
• An actor is a user of a system in a
particular role.
BookBorrower
Borrow book
23
An actor can be human or an external
system.
• A use case is a a task that an actor
needs to perform with the help of the
system.
CS 501 Spring 2002
Use Cases and Actors
• A scenario is an instance of a use case
• Actor is role, not an individual
(e.g., librarian can have many roles)
• Actor must be a "beneficiary" of the use case
(e.g., not librarian who processes book when borrowed)
In UML, the system boundary is the set of use cases.
24
CS 501 Spring 2002
Use Cases for Borrowing Books
Borrow copy
of book
BookBorrower
Return copy
of book
Reserve
book
Extend
loan
25
CS 501 Spring 2002
Relationships Between Use Cases:
<<uses>>
Extend
loan
BookBorrower
26
Borrow copy
of book
<<uses>>
Check for
reservation
<<uses>>
CS 501 Spring 2002
Relationships Between Use Cases:
<<extends>>
BookBorrower
27
<<extends>>
Borrow copy
of book
Refuse
loan
CS 501 Spring 2002
Use Cases in the Development Cycle
• Use cases are a tool in requirements analysis
• Intuitive -- easy to discuss with clients
• Use cases are often hard to translate into class models
• Scenarios are useful to validate design
28
CS 501 Spring 2002
An Exam Question:
Object Oriented Design
A system generates weather maps using data collected from
unattended weather stations. Each weather station collects
meteorological data and produces summaries of the data.
On request, it sends the summary information to an area
computer. The area computer uses a database of digitized
maps to generate a set of local weather maps.
29
CS 501 Spring 2002
Exam Question: Noun Identification
A system generates weather maps using data collected from
unattended weather stations. Each weather station collects
meteorological data and produces summaries of the data.
On request, it sends the summary information to an area
computer. The area computer uses a database of digitized
maps to generate a set of local weather maps.
30
CS 501 Spring 2002
Exam Question: Candidate Classes
System
general term
WeatherMap
Data
same as MeteorologicalData
WeatherStation
is this a general term?
MeteorologicalData
how does this relate to WeatherStation?
DataSummary
how does this relate to MeteorologicalData?
AreaComputer
hardware
Database
general term
DigitizedMap
31
CS 501 Spring 2002
Exam Question: Observations about
the Candidate Classes
WeatherMap
is a DigitizedMap
is derived from 1...* DataSummary
WeatherStation
has a set of MeteorologicalData
MeteorologicalData
DataSummary
is derived from MeteorologicalData
DigitizedMap
Can Meteorological Data be an attribute of WeatherStation?
Can DataSummary be combined with WeatherMap?
32
CS 501 Spring 2002
Exam Question: Attributes and
Operations
WeatherStation
location
metereologicalData
collectData()
getSummary()
DigitizedMap
location
geographicData
printMap()
33
WeatherMap
location
date-time
geographicData
weather
gatherData()
printMap()
Or should
MetereologicalData be a
separate object?
CS 501 Spring 2002
Exam Question: Class Diagram
DigitizedMap
WeatherStation
location
metereologicalData
collectData()
getSummary()
WeatherMap
1
1...*
summary
location
date-time
geographicData
weather
gatherData()
printMap()
34
CS 501 Spring 2002
Download