Lect 14
Lect 14
Analysis and
Design
1
OOAD
OOA OOD/OOP
Domai
Specification Definition n Construction
of Model of Progra
the problem Use the solution m
case
model
2
OOA versus OOD?
Analysis:
An elaboration of requirements.
Independent of any specific
implementation
Design:
A refinement of the analysis model.
Takes implementation constraints into
account
3
Design Process
OOA OOD
User interface
Issues or GUI
Use case Interaction
prototype diagram diagram
Start
Glossary
4
Domain Modelling
Represent objects appearing in the
problem domain.
Also capture object relationships.
Three types of objects are identified:
Boundary objects
Entity objects
Controller objects
5
Boundary Objects
Handle interaction with actors:
User interface objects
Often implemented as screens, menus,
forms, dialogs etc.
These do not perform any processing:
But may only validate input, format
output, etc.
6
Entity Objects
Hold information over long term:
e.g. Book, BookRegister, Member
Normally are dumb servers:
Responsible for storing data, fetching
data etc.
Elementary operations on data such as
searching, sorting, etc.
Often appear as nouns in the problem
7
description...
Controller Objects
Help to realize use case behavior:
Interface with the boundary objects
Coordinate the activities of a set of entity
objects
Embody most of the business logic:
Take overall responsibility for use case
execution.
Usually a use case is realized by one
controller.
8
Controller Classes
Controller classes coordinate,
sequence, transact, and otherwise
control other objects… Controll
er
Name controller attributed to
Smalltalk MVC mechanism:
Where such objects were
called controllers…
Boundar Entity
y
9
Example Use Case Realization
register
Customer customer Clerk
Manager Supermarket
Prize scheme
11
Identification of Controller Objects
Examine the use case diagram:
Add one controller class for each use case.
Later on, some controllers may be removed or may
need to be split into two or more controller classes
if they have too much responsibility.
register
Customer customer Clerk
register
Play Move sales
Sales Clerk
select
Tic-tac-toe game
Player winners
Supermarket
Manager Prize scheme
12
Identification of Entity Objects
Usually appear as common nouns in the
problem description.
From the list of nouns, need to exclude:
Users (e.g. accountant, librarian, etc)
Passive verbs (e.g. Acknowledgment)
Those with which you can not associate any methods
Those with which you can not associate any data to
store
Surrogate users may exist as classes:
Library member
13
Identify Classes
A partial requirement:
The user must be allowed to specify each product by
its primary characteristics, including its name and
product number. If the bar code does not match the
product, then an error should be generated to the
message window and entered into the error log. The
summary report of all transactions must be structured
as specified in section 7.A.
Of course, not all nouns will correspond to a
class or object in the final solution
14
Identify Entity Classes
Eliminate improbable nouns:
The user must be allowed to specify each product by
its primary characteristics, including its name and
product number. If the bar code does not match the
product, then an error should be generated to the
message window and entered into the error log. The
summary report of all transactions must be structured
as specified in section 7.A.
16
Identify Classes by Noun Analysis
A partial requirements document:
17
It is Challenging to Identify Classes!
Example:
The aggregator *
CustomerRecor
corresponds to registers d
in the physical world
19
Naming Classes
Class names should be singular nouns
Examples: Member, Student, Book
20
Example 1: Tic-Tac-Toe Computer Game
A human player and the computer make
alternate moves on a 3X3 square.
A move consists of marking
a previously unmarked square.
The user inputs a number
between 1 and 9 to mark a square
Whoever is first to place three consecutive
marks along a straight line (i.e., along a row,
column, or diagonal) on the square wins.
21
Example 1: Tic-Tac-Toe Computer Game cont…
As soon as either of the human player or the
computer wins,
A message announcing the winner should be
displayed.
If neither player manages to get three
consecutive marks along a straight line,
And all the squares on the board are filled up,
Then the game is drawn.
The computer always tries to win a game. 22
Example 1: Tic-Tac-Toe
Use Case Model
Play Move
Tic-tac-toe game
Player
23
Example 1: Initial and Refined
Domain Model
Board
PlayMoveBounda PlayMoveControll
ry er
Board
24
Example 1: Sequence Diagram
:playMove :playMove
Boundary Controller
:board
acceptMove checkMoveValidity
move
[invalidMove] [invalidMove]
announceInvalidMove
announceInvalidMove checkWinner
[game over]
[game over] announceResult
announceResult
playMove
checkWinner
[game over] [game over]
announceResult announceResult
displayBoardPositions getBoardPositions
[game not over]
promptNextMove
Board PlayMoveBoundary
int position[9]
checkMove Validity announceInvalidMove
checkResult announceResult
playMove displayBoard
Controller
announceInvalidMove
announceResult
26
Domain Modelling Example 2: Supermarket Prize
Scheme
A supermarket needs to develop software to
encourage regular customers.
A customer needs to supply:
Residence address, telephone
number, and driving licence number to register.
Each customer who registers:
Assigned a unique customer number (CN) by
the computer.
27
Example 2: Supermarket Prize Scheme
A customer can present his CN to the staff
when he makes any purchase.
The value of his purchase is credited
against his customer’s CN.
At the end of each year:
The supermarket awards
surprise gifts to ten customers who
make highest purchase. 28
Example 2: Use Case Model
register
Customer customer Clerk
register
sales
Sales Clerk
select
winners
Manager Supermarket
Prize scheme
29
Example 2: Initial Domain Model
CustomerRegis
SalesHistory
ter
1 1
* *
CustomerRecor
SalesRecords
d
30
Example 2: Refined Domain Model
CustomerRegiste
SalesHistory
r
1 1
* *
SalesRecords CustomerRecord
RegisterCustomerBoun RegisterCustomerContr
dary oller
RegisterSalesBoundary RegisterSalesController
SelectWinnersControlle
SelectWinnersBoundary
rs
31
Example 2: Sequence Diagram for
the Register Customer Use Case
register
register
checkDuplicate
*match
[duplicate]
[duplicate]
showError
showError
generateCIN
:Register :Register
:Sales
Sales Sales
History
Boundary Controller
RegisterSales registerSales
registerSales
create :Sales
Record
confirm
confirm
33
Sequence Diagram for the register sales use case
Example 2: Sequence Diagram for the
Select Winners Use Case
Select
SelectWinners
Winners
SelectWinners
*computeSales
*check
selectWinners findWinnerDetails
registerSales register
1 1
* *
SalesRecords CustomerRecord
salesDetails name
address
computerSales browse
check checkDuplicate
35
create create
Exercise 0: Construct Domain Model
The fleet of vehicles at a travel agency consists of
vehicles of the types Tata Indica, Maruti van, and
Mahindra Xylo.
Customers first register by providing their details
and depositing Rs.5000/- with the agency.
The details of the customers such as the name,
address, and phone number are maintained by
the agency in a customer register.
The registered customers are allowed to rent any
vehicle. The details of the travel, date, distance,
AC/NonAC are entered by the driver.
36
Solution
Vehicle
Registe
* Vehicl
e
r
*
Indic Van Xyl Renta
a o l
*
Custom
er
* Custom
er
Register
37
Refined Solution
Vehicle
* Vehicl
Registe
e *
r
Custom
er
* Custom *
er
Register
38
A country has many airports. Exercise 2
A set of flights arrive and depart from each airport.
Each flight is characterized by its flight number,
origin and destination airports, scheduled times at
the origin and destination, and days of week in
which it operates.
A passenger can book a flight for a specific date.
Each passenger has a name, a mobile number, and
address.
A flight booking is characterized by a transaction
number, ticket Price, and any special amenities
booked (such as preordered meals).
39
Solution
Count * Airpor
ry t
Departs Arrives
Passeng
has * Bookin
er g
* *
Flight
40
Spencer’s retail has set up stores in various
cities, and some cities have up to 10 stores.
Customers register in a store during their first
visit. Each store maintains a set of registered
customers.
Exercise 3
Registered customers may buy merchandise
from any of the other stores.
Dates of their various store visits and purchases
must be kept track of.
Each customer accrues bonus points based on his
purchases.
41
Solution
City
0..10
Spence * Store
r *
Purchas
e
* visits
Custom
er *
42
Each institute has many students and many
Departments.
A Department offers many courses, but someExercise
courses
may be offered jointly by two departments. 4
Each Department has many instructors. Each
instructor can be given joint appointment in upto two
Departments. Some instructors are professors, while
others are associate and assistant professors. One of
the instructors of a Department also serves as the
Head of the department.
Courses are taught by instructors, who may teach up
to three courses. A course can be taught by upto 2
teacher
A student needs to complete 30 courses, but can take
only upto 7 courses every semester. The names of the
43
credited courses and the grades obtained in them by
0..1 HoD of
assigned to
Institute * Department
1..2
*
1..2
Instructor
1..2
offers
teaches
Registrati
on
* * 0..3
44
45
CRC Cards
Used for systematically assigning
responsibilities (methods) to classes.
Complex use cases:
Realized through
collaborative actions of dozens of classes.
Pioneered by Ward Cunningham and
Kent Beck.
Index cards prepared one per each
class.
BookRegister
Contains columns for: FindBook Book
CreateBook Book
Class responsibility Reserve Book
Collaborating objects
47
CRC Cards: Working
Systematize development of the
interaction diagram for complex use
cases.
Team members
participate to determine:
The responsibility of classes involved in a
use case realization…
48
CRC Card Cont…
BookRegister
Responsibility: FindBook Book
Method to be CreateBook Book
Collaborator:
Class whose service (method) would have
to be invoked…
49
An Example of A CRC Card
Class name
BookRegister
FindBook Book
CreateBook Book
Reserve Book
Responsibility Collaborator
53
3. IIT Security Software
The staff and students of IIT register their vehicle by filling up a form which a
security staff would enter into the system.
Each time a vehicle enters or leaves the campus, a camera reads the
registration number of the car, and the model of the car. If the car is
registered, the check gate should lift automatically to let in (or out) the
vehicle. The details regarding the entry and exit of the vehicle are registered
in the database. For outside vehicles, the driver needs to enter the purpose of
entry, the model number, the registration number, and a photograph of the
vehicle is stored in the database.
When an outside vehicle leaves the campus, the details are automatically
registered in the database. For any external vehicle that is inside the campus
for more than 8 hours, the driver is stopped by the security personnel
manning the gate, queried to satisfaction, and the response are recorded.
Considering that there have been several incidence of speeding and rough
driving, the security personnel are empowered to telephone the registration
number of errant vehicles to the main gate. For outside vehicles, the driver is
quizzed at the check gate and his future entry is barred if the response is not
satisfactory. For inside vehicles, a letter is issued to the dean to deal with the
employee or student as the case might be.
The security officer can check the data regarding the number of vehicles going
in and coming out of the campus (over a day, month or year), the total
number of vehicles currently inside the campus.
54
4. Students’ Auditorium Management
Software
Various types of social and cultural events are conducted in the
student auditorium. There are two categories of seats: balcony and
ordinary seats. The maximum number of balcony seats that can be
booked per ticket is 2.
The show manager fixes the prices of the two categories of seats for
a specific show, depending on the popularity of a show.
The show manager also enters the show dates, the number of shows
on any particular date and the show timings. It is expected that the
software would support a functionality to let the show manager
configure the different show parameters.
The system should let the spectators query the availability of
different classes of seats for a show on-line. A spectator can book a
seat for a single show only through regular cash payment and the
software should print out the ticket showing the seat numbers
allocated. A spectator should be able to cancel his booking before 3
clear days of the show.
55
5. Travel Agency Automation
Software
The company owns a number of vehicles (cars and SUVs) of various make and intends to
deploy a web-based software. A customer can become regular customer by depositing Rs.
5,000/- and supplying his name address, and mobile phone number.
When a customer requests for a car, he is displayed the types of vehicles are available,
and their charges. For every vehicle, there is a per hour charge, and a per kilometer
charge. A vehicle can be rented for a minimum of 4 hours. An AC vehicle of a particular
category is charged 50% more than a non-AC vehicle of the same category. There is a
charge of Rs 300 for every night of halt regardless of the type of the vehicle.
A customer can book a vehicle, only if he has at least Rs. 2000/- advance. The customer
needs to enter when he expects to return the car. When the car is returned, depending on
the usage, if possible the amount is fully adjusted from the advance, or he has to pay
additional amount to cover the cost incurred.
The company can acquire new vehicles and add them to the fleet of its vehicles. Cars may
be condemned and sold off. A car which is currently with the company can be in one of
three states: it may have gone for repair, it may be available, it may be rented out. If it is
rented out, the company records the date and time when it has been rented out, and the
mile-meter reading of the car at that time.
The company also wants to maintain the maintenance and running expense for each
vehicle.
The manager of the company should be able to query statistics about various types of
vehicles, their prices, average expense on repairs for the car, average demand, revenue
earned, and fuel consumption of the car.
56
6. Newspaper Delivery Automation System
The local newspaper and magazine delivery agency has asked us to
develop a software for him to automate various clerical activities
associated with his business.
The customers usually subscribe one or more news papers and
magazines. Customers should be able to initiate new subscriptions
and suspend subscription for a particular item either temporarily or
permanently through a web browser•
The customers may ask for stopping the deliveries to them for
certain periods when they go out of station.
For each delivery person, the system must print each day the
publications to be delivered to each address. The system should
also print for the news agent the information regarding who
received what and a summary information of the current month.
At the beginning of every month bills are printed by the system to
be delivered to the customers. These bills should be computed by
the system automatically.
The manager must be able to view the total receipts every month.
57
7. Restaurant Automation
Software
The computer should maintain the prices of all the items:
Also support changing the prices by the manager.
Whenever any item is sold:
The sales clerk would enter the item code and the quantity sold.
The computer should generate bills and register the payments.
Whenever ingredients are issued for preparation of food items,
the data is to be entered into the computer.
Purchase orders are generated on a daily basis, for all ingredients
whose stock falls below a threshold value.
The threshold value for each item is computed based on the average
consumption for the past three days and assuming that two days stock must be
maintained.
Whenever the ordered ingredients arrive, the invoice data regarding
the quantity and price is entered.
If sufficient cash balance is available, the computer should print cheques
against invoice.
Monthly sales receipt and expenses data should be generated
whenever the manger would request to see them.
58
8. City Road Maintenance System
A city corporation has branch offices at different suburbs of the city. Residents would
raise repair requests for different roads of the city on line.
The supervisor at each branch office should be able to view all new repair requests
pertaining to his area.
The supervisor visits the road and studies the severity of road condition and the raw material requirement
for carrying out the repair work, the types and number of machines required, and the number and types
of personnel required.
The supervisor enters this information through a special login in the web site.
Based on this data, the system should schedule the repair of the road depending on
the priority of the repair work and subject to the availability of raw material, machines,
and personnel.
This schedule report is used by the supervisor to direct different repair work.
The manpower and machine that are available are entered by the city corporation
administrator. He can change these data any time.
The progress of the work is entered periodically by the supervisor which can be seen
by the citizens in the web site.
The mayor of the city can request for various road repair statistics such as the number
and type of repairs carried out over a period of time and the repair work outstanding
at any point of time and the utilization statistics of the repair manpower and machine
over any given period of time.
59
9. Bookshop Automation Software
BAS should help the customers query whether a book is in stock. The users can
query the availability of a book either by using the book title or by using the name
of the author.
If the book is not currently being sold by the book-shop, then the customer is
asked to enter full details of the book for procurement of the book in future. The
customer can also provide his e-mail address, so that he can be intimated
automatically by the software as and when the book copies are received.
If a book is in stock, the exact number of copies available and the rack number in
which the book is located should be displayed. If a book is not in stock, the query
for the book is used to increment a request field for the book.
BAS should maintain the price of various books.
As soon as a customer selects his books for purchase, the sales clerk would enter
the ISBN numbers of the books. BAS should update the stock, and generate the
sales receipt for the book.
BAS should allow employees to update the inventory whenever new supply
arrives.
Upon request by the owner of the book shop, BAS should generate sales statistics
(viz., book name, publisher, ISBN number, number of copies sold, and the sales
revenue) for any period.
60
10: Video Rental Store Automation
The store has a large collection of video CDs and DVDs in VHS and MP4 format as
well as music CDs.
A person can become member by depositing Rs. 1000 and filling up name,
address, and telephone number. A member can cancel his membership and take
back his deposit, if he has no dues outstanding against him.
Whenever the store purchases a new item, the details such as date of
procurement and price are entered. The daily rental charge is also entered by the
manager. After passage of a year, the daily rental charge is automatically halved.
A member can take on loan at most one video CD and one music CD each time.
The details are entered by a store clerk and a receipt indicating the daily rental
charge is printed.
Whenever a member returns his loaned item, the amount to be paid is displayed.
After the amount is paid, the items are marked returned.
If a customer loses or damages any item, the full price of the item is charged to
him and the item is removed from the inventory.
If an item lies unissued for more than a year, it is sold to the members at 10% of
the purchase price and the item is removed from the inventory.
The manager can at any time check the profit/loss account.
61