software engineering :behavioral modelling - i sequence diagram
TRANSCRIPT
Software Engineering Principles
Ajit K Nayak, Ph.D.
Domain & Behavioural Modelling
Acknowledgements• Slides of Prof. Rajib Mall, IIT, KGP
Domain Modelling• Represents concepts or objects appearing in the
problem domain.
• Also captures relationships among objects.
• Three types of objects are identified
– Boundary objects
– Entity objects
– Controller objects
• Three different stereotypes on classes are used:
– <<boundary>>
– <<entity>>
– <<control>>
Cashier Interface
Withdrawal
Account
Object Types• Boundary Objects are objects that Interact with actors:
– User interface objects like screens, menus, forms, dialogs etc.
– Do not perform processing but validates, formats etc.
• Entity Objects are objects that Hold information:– Such as data tables & files, e.g. Book, BookRegister
– Normally are dumb servers responsible for storing data, fetching data etc.
– Elementary operations on data such as searching, sorting, etc.
– Entity Objects are identified by examining nouns in problem description
• Controller Objects Coordinate the activities of a set of entity objects– Interface with the boundary objects
– Realizes use case behaviour– Embody most of the logic involved with the use case
realization
– There can be more than one controller to realize a single use case
Modelling Behaviours• A behavioural model
shows the interactions between objects to produce some particular system behaviour that is specified as a use-case.
• Sequence diagrams, Activity diagrams, state diagrams, collaboration diagrams are used to model interaction between objects.
• Where are people coming from?
• Where are they going?
• How do they move from one space to the other?
Modelling Behaviour
• How do we use the SMS Server interface?
• What is the order of executing the operations?– sendMessage, getStatus, Resend?
– getStatus, sendMessage, checkForMessages?
• When do we use resend?
• We use Interaction diagrams to model this
Phone
handleMessage(text, reciepient)
SMS Server
sendMessage(sender, text, reciepient):msgID
getStatus(msgID): status
resend(msgID)
checkForMessages(receipient):msgID[]
Sequence Diagrams• A sequence diagram is an interaction diagram that
shows how objects send messages with one another and in what order?
Object Control
Corresponding Class Diagram
Message types• Synchronous message
– Used when the sender waits until the receiver has finished processing the message, only then does the caller continue (i.e. a blocking call).
• Asynchronous message– the sender does not wait for the
receiver to finish processing the message.
– An open arrowhead is used to indicate that a message is sent asynchronously.
• Return message
If-Else (Alternatives)
Loops - Iteration
Example 1: Tic-Tac-Toe Computer Game
• A human player and the computer make alternate moves on a 33 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.
• 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, – All the squares on the board are filled up,
– Then the game is drawn.
• The computer always tries to win a game.
Domain Modelling• Use Case Model
Tic-tac-toe game
Play Move
Player
• Initial and Refined Domain Model
Board
Initial domain model
PlayMoveBoundary PlayMoveController Board
Refined domain model
Sequence Diagram
:playMoveBoundary
:playMoveController
:board
move acceptMove checkMoveValidity
[invalidMove]announceInvalidMove
[invalidMove]
announceInvalidMove
[game over]announceResult
announceResult[game over]
checkWinner
playMove
checkWinner
[game over]announceResult
[game over]announceResult
getBoardPositionsdisplayBoardPositions
[game not over]promptNextMove
Class Diagram
Board
int position[9]
checkMove ValiditycheckResultplayMove
Controller
announceInvalidMoveannounceResult
PlayMoveBoundary
announceInvalidMoveannounceResultdisplayBoard
Supermarket Prize Scheme - I• Supermarket needs to develop software to encourage
regular customers.
• Customer needs to supply his:
– Residence address, telephone number, and the
driving licence number.
• Each customer who registers is:
– Assigned a unique customer number (CN) by the
computer.
• A customer can present his CN to the staff when he makes any purchase.
– The value of his purchase is credited against his CN.
Supermarket Prize Scheme - II• At the end of each year:
– The supermarket awards surprise gifts to ten
customers who make highest purchase.
• Also, it awards a 22 carat gold coin to every customer:
– Whose purchases exceed Rs. 10,000.
• The entries against the CN are reset:
– On the last day of every year after the prize winner’s
lists are generated.
Use Case Model
SupermarketPrize scheme
registercustomer
registersales
selectwinners
Customer
Sales Clerk
Manager
Clerk
Initial Domain Model
SalesHistory
SalesRecords
1
*CustomerRecord
CustomerRegister
1
*
Refined Domain Model
SalesHistory
SalesRecords
1
*CustomerRecord
CustomerRegister
1
*
RegisterCustomerBoundary
RegisterSalesBoundary
SelectWinnersBoundary
RegisterCustomerController
RegisterSalesController
SelectWinnersControllers
Sequence Diagram:Select Winners Use Case
:SelectWinnerBoundary
:SelectWinnerController
:SalesHistory
:SalesRecord
:CustomerRegister
:CustomerRecord
SelectWinners
SelectWinners
announces
SelectWinners*computeSales
*browse
[for each winner]find WinnerDetails [for each winner]
browse
Sequence Diagram: Register Customer Use Case
:RegisterCustomerBoundary
:RegisterCustomerController
:CustomerRegister
:CustomerRecord
registerregister
*match
displayCIN
create:CustomerRecord
checkDuplicate
[duplicate]
showError
generateCIN
register
showError
Sequence Diagram: Register Sales Use Case
:SalesRecord
create
RegisterSales
:RegisterSales
Boundary
:SalesHistory
:RegisterSales
Controller
registerSales
confirm
registerSales
confirm
Sequence Diagram: Refined Register Sales Use Case
:RegisterSales
Boundary
:SalesHistory
registerSales
confirm
:SalesRecord
create
RegisterSales
Class Diagram
SalesHistory
selectWinnersregisterSales
CustomerRegister
findWinnerDetailsregister
SalesRecords
computerSalesbrowsecreate
salesDetails
CustomerRecord
browsecheckDuplicatecreate
nameaddress
1
*
1
*
Thank You