Sequence Diagrams

advertisement
Sequence Diagrams
USE CASE :
In its simplest form, a use case can be described as a specific way of using the system
from a user’s (actor’s) perspective. A more detailed description might characterize a use
case as:
·
a pattern of behavior the system exhibits
·
a sequence of related transactions performed by an actor and the system
·
delivering something of value to the actor
Use cases provide a means to:
·
capture system requirements
·
communicate with the end users and domain experts
·
test the system
Use cases are best discovered by examining the actors and defining what the actor will be
able to do with the system.
The basic shape of a use case is an ellipse:
Display
SEQUENCE DIAGRAM
A sequence diagram is a graphical view of a scenario that shows object interaction in a
time-based sequence of what happens first - what happens next. Sequence diagrams
establish the roles of objects and help provide essential information to determine class
responsibilities and interfaces. This type of diagram is best used during early analysis
phases in design because they are simple and easy to comprehend. Sequence diagrams are
normally associated with use cases.
A sequence diagram has two dimensions: typically, vertical placement represents time
and horizontal placement represents different objects.
Typically one has one sequence diagram per use case.
Following is the class diagram of the Person and the PersonList problem
The functionalities present in this problem are
1. Adding a person to the PersonList
2. Displaying the list
Class Diagram
The use case diagram will be
User
addPerson
Display
How to create a use case
1. To add an actor right click on the “Use Case View” folder . Select New->Actor.
Name the actor accordingly
2. To add a use case click on the “Use Case View” folder . Select New->Use Case.
3. Draw associations by selecting the association arrow from the tool box.
SEQUENCE DIAGRAMS
The next step is to create a sequence diagram for each use case.
How to create a sequence diagram
1. Right click on the “Use Case View” folder and select New -> Sequence Diagram
2. Name your sequence diagram (Add Person in our example)
3. Drag the actor and the required classes from the left panel on to the diagram
space. You will get something looking like this.
: User
: PersonList
: Person
4. Click on the arrow on your toolbox (Object Message). Draw the arrow from Actor
to Person list.
5. Right Click on the arrow. You will find a list of methods of PersonList class
listed. Select the appropriate method.
6. Repeat step 5 for all messages needed.
For our example, the actor first calls the addPerson() method of personList. The
personList then calls the setName() and setAge() methods of the Person class.
The sequence diagram will be as follows:
: User
: PersonList
: Person
addPerson(char*, char*, int)
setName(char*, char*)
setAge(int)
As you can see the diagram shows the sequence of methods called to add a person in the
List. The vertical long boxes below the objects signify the life of the objects. (As
‘Person’ is owned by ‘PersonList’, the it’s life is smaller than “PersonList’s” life and
hence the box below ‘Person’ is smaller too.)
Similarly the sequence diagram for the Display use case will look like this
: PersonList
: User
display( )
: Person
display( )
Assignment : Load your O1 object model and create a sequence diagram for a sale
processing.(‘Sale Processing’ is one of the use cases for the O1 problem where the actor
could be the ‘Store Keeper’).
Download