27
Software Engineering Principles Ajit K Nayak, Ph.D. [email protected] Domain & Behavioural Modelling

Software Engineering :Behavioral Modelling - I Sequence diagram

Embed Size (px)

Citation preview

Page 1: Software Engineering :Behavioral Modelling - I Sequence diagram

Software Engineering Principles

Ajit K Nayak, Ph.D.

[email protected]

Domain & Behavioural Modelling

Page 2: Software Engineering :Behavioral Modelling - I Sequence diagram

Acknowledgements• Slides of Prof. Rajib Mall, IIT, KGP

Page 3: Software Engineering :Behavioral Modelling - I Sequence diagram

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

Page 4: Software Engineering :Behavioral Modelling - I Sequence diagram

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

Page 5: Software Engineering :Behavioral Modelling - I Sequence diagram

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?

Page 6: Software Engineering :Behavioral Modelling - I Sequence diagram

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[]

Page 7: Software Engineering :Behavioral Modelling - I Sequence diagram

Sequence Diagrams• A sequence diagram is an interaction diagram that

shows how objects send messages with one another and in what order?

Page 8: Software Engineering :Behavioral Modelling - I Sequence diagram

Object Control

Page 9: Software Engineering :Behavioral Modelling - I Sequence diagram

Corresponding Class Diagram

Page 10: Software Engineering :Behavioral Modelling - I Sequence 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

Page 11: Software Engineering :Behavioral Modelling - I Sequence diagram

If-Else (Alternatives)

Page 12: Software Engineering :Behavioral Modelling - I Sequence diagram

Loops - Iteration

Page 13: Software Engineering :Behavioral Modelling - I Sequence diagram

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.

Page 14: Software Engineering :Behavioral Modelling - I Sequence diagram

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

Page 15: Software Engineering :Behavioral Modelling - I Sequence diagram

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

Page 16: Software Engineering :Behavioral Modelling - I Sequence diagram

Class Diagram

Board

int position[9]

checkMove ValiditycheckResultplayMove

Controller

announceInvalidMoveannounceResult

PlayMoveBoundary

announceInvalidMoveannounceResultdisplayBoard

Page 17: Software Engineering :Behavioral Modelling - I Sequence diagram

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.

Page 18: Software Engineering :Behavioral Modelling - I Sequence diagram

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.

Page 19: Software Engineering :Behavioral Modelling - I Sequence diagram

Use Case Model

SupermarketPrize scheme

registercustomer

registersales

selectwinners

Customer

Sales Clerk

Manager

Clerk

Page 20: Software Engineering :Behavioral Modelling - I Sequence diagram

Initial Domain Model

SalesHistory

SalesRecords

1

*CustomerRecord

CustomerRegister

1

*

Page 21: Software Engineering :Behavioral Modelling - I Sequence diagram

Refined Domain Model

SalesHistory

SalesRecords

1

*CustomerRecord

CustomerRegister

1

*

RegisterCustomerBoundary

RegisterSalesBoundary

SelectWinnersBoundary

RegisterCustomerController

RegisterSalesController

SelectWinnersControllers

Page 22: Software Engineering :Behavioral Modelling - I Sequence diagram

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

Page 23: Software Engineering :Behavioral Modelling - I Sequence diagram

Sequence Diagram: Register Customer Use Case

:RegisterCustomerBoundary

:RegisterCustomerController

:CustomerRegister

:CustomerRecord

registerregister

*match

displayCIN

create:CustomerRecord

checkDuplicate

[duplicate]

showError

generateCIN

register

showError

Page 24: Software Engineering :Behavioral Modelling - I Sequence diagram

Sequence Diagram: Register Sales Use Case

:SalesRecord

create

RegisterSales

:RegisterSales

Boundary

:SalesHistory

:RegisterSales

Controller

registerSales

confirm

registerSales

confirm

Page 25: Software Engineering :Behavioral Modelling - I Sequence diagram

Sequence Diagram: Refined Register Sales Use Case

:RegisterSales

Boundary

:SalesHistory

registerSales

confirm

:SalesRecord

create

RegisterSales

Page 26: Software Engineering :Behavioral Modelling - I Sequence diagram

Class Diagram

SalesHistory

selectWinnersregisterSales

CustomerRegister

findWinnerDetailsregister

SalesRecords

computerSalesbrowsecreate

salesDetails

CustomerRecord

browsecheckDuplicatecreate

nameaddress

1

*

1

*

Page 27: Software Engineering :Behavioral Modelling - I Sequence diagram

Thank You