6. Car Rental Case Study in UML •
To follow: A medium sized case study for a car rental administration system
•
Explanation of central UML diagrams and language features therein
•
•
•
Used here: Use case, class, object, statechart, sequence, collaboration, and activity diagrams Development of the case study also demonstrates a typical development process Diagram order in this document does not reflect the order occurring in the development
6. Car Rental - Overview on the Used Development Process (1) Start with a use case diagram giving an overview on the system, its boundaries and its main functionality (2) Develop object diagrams and sequence diagrams as desired scenarios for the system structure and behavior (3) Develop a class diagram and a statechart diagram for each class; start with a textual description of the statechart diagrams; continue with a more formal description for the statecharts (4) Check whether the existing object diagrams and sequence diagrams are consistent with the class diagram and the statechart diagrams; if neccessary, modify them (5) Develop more object and sequence diagrams (6) If an operations seems to become stable (no changes in the diagrams for the parts with that operation), start to develop activity diagrams for that operation; begin with a textual description and advance to a more formal one (7) Repeat steps (4)-(6) until an acceptable model is found
6. Car Rental - Use Case Diagram Car Rental System A real world customer
is outside the Car Rental System, customer within that system.
create customer
a
create car
book
request cancel
user
pickUp real world customer
billing return
<
>
<>
<>
PersistentStore
early return billing clerk
late return
6. Car Rental - Details for Use Case create customer Use Use case case name name: : crea create te cust custom omer er Goal Goal: : to crea create te a new new cust custom omer er Prec Precon ondi diti tion on: : the the real real worl world d cust custom omer er to be reco record rded ed is currentl currently y not represen represented ted Postco Postcondi nditio tion: n: a new custom customer er exists exists Actors Actors: : user user Trig Trigge geri ring ng even event: t: a real real worl world d cust custom omer er must must be reco record rded ed Descripti Description: on: Extension Extensions: s: Alternati Alternatives: ves: -
6. Car Rental - Details for Use Case create car Use Use case case name name: : crea create te car car Goal Goal: : to crea create te a new new car car Prec Precon ondi diti tion on: : the the real real worl world d car car to be reco record rded ed is currentl currently y not represen represented ted Post Postco cond ndit itio ion: n: a new new car car exis exists ts Actors Actors: : user user Trig Trigge geri ring ng even event: t: a real real worl world d car car must must be reco record rded ed Descripti Description: on: Extension Extensions: s: Alternati Alternatives: ves: -
6. Car Rental - Details for Use Case book Use Use case case name name: : book book Goal Goal: : to ente enter r a car car rent rental al book bookin ing g Precon Precondit dition ion: : the bookin booking g detail details s are plausi plausible ble Post Postco cond ndit itio ion: n: a new new book bookin ing g exis exists ts; ; the the book bookin ing g is now now an open open book bookin ing g Actors Actors: : user user Trig Trigge geri ring ng even event: t: a real real worl world d cust custom omer er requ reques ests ts a book bookin ing g Desc Descri ript ptio ion: n: the the real real worl world d cust custom omer er want wants s to rent rent a real real worl world d car car of a cert certai ain n cate catego gory ry; ; star start t day day of the the rent rental al is the the curr curren ent t day day or a day day after fter the curr curren ent t day day; end end day day of the the rent rental al lies lies afte after r the the star start t day day Extension Extensions: s: Alternati Alternatives: ves: -
6. Car Rental - Details for Use Case cancel Use Use case case name name: : canc cancel el Goal Goal: : to prev preven ent t that hat a car must ust be pick picked ed up for for a booki ookin ng Prec Precon ondi diti tion on: : the the book bookin ing g to be canc cancel eled ed is pres presen ent t Post Postco cond ndit itio ion: n: the the book bookin ing g is mark marked ed as clos closed ed; ; no car car will will be pick picked ed up for for this this book bookin ing g Actors Actors: : user user Trig Trigge geri ring ng even event: t: a real real worl world d cust custom omer er requ reques ests ts a cancel cancelati ation on of a bookin booking g Descripti Description: on: Extension Extensions: s: Alte Altern rnat ativ ives es: : trig trigge geri ring ng even event t - the the star start t day day of a book bookin ing g is passe assed d and and no car car has has been een pick picked ed up by the the custo ustome mer r for that that bookin booking g
6. Car Rental - Details for Use Case pickUp Use Use case case name name: : pick pickUp Up Goal Goal: : to deli delive ver r a car for for a car car ren rental tal Precon Precondit dition ion: : a bookin booking g is presen present t Post Postco cond ndit itio ion: n: a suit suitab able le car car is mark marked ed as unav unavai aila labl ble e (a real real worl world d car car is give given n to a real real worl world d cust custom omer er); ); the the bookin booking g become becomes s a curren current t bookin booking g Actors Actors: : user user Trig Trigge geri ring ng even event: t: a real real worl world d cust custom omer er requ reques ests ts a pick pick up Desc Descri ript ptio ion: n: a suit suitab able le car car must must be foun found d amon among g the the curr curren entl tly y avai availa labl ble e cars cars; ; if none none is pres presen ent, t, a new new car car may may be adde added d (a new new real real worl world d car car is purc purcha hase sed) d) Extension Extensions: s: Alternati Alternatives: ves: -
6. Car Rental - Details for Use Case return Use Use case case name name: : retu return rn Goal Goal: : to retu return rn a car car for for a car rent ental Prec Precon ondi diti tion on: : a curr curren ent t book bookin ing g exis exists ts and and a car car has has been been delivered Postco Postcondi nditio tion: n: the bookin booking g become becomes s closed closed; ; the car become becomes s avai availa labl ble e (rea (real l worl world d cust custom omer er has has retu return rned ed real real worl world d car) car) Actors Actors: : user user Trig Trigge geri ring ng even event: t: a real real worl world d cust custom omer er requ reques ests ts a retu return rn on the the end end day day of the the book bookin ing g Descripti Description: on: Extensions: earl early y retu return rn: : a rent rented ed car car is retu return rned ed befo before re the the end end date date of the the book bookin ing g late late retu return rn: : a rent rented ed car car is retu return rned ed afte after r the the end end date date of the bookin booking g Alternati Alternatives: ves: -
6. Car Rental - Class Diagram Customer Car
Name : String
<>
<>
DateT
CatET
Day : Integer <<1..31>> Month : Integer <<1..12>> Year : Integer <<1900..2100>>
E / economy
LicenceNo : String
create (n:String):Customer
Cat : CatET
book(s:DateT,e:DateT,ct:CatET) cancel(b:Booking) pickUp(b:Booking):Car return(cr:Car)
S / standard
create (l:String,ct:CatET):Car
L / luxus
0..1 car 1 customer
Assignment
Registration
"only correct dates"
0..* booking searchAvailCar():Car post Cat<=result.Cat and result.available
0..1 booking
car : Car
car : Set(Car)
Booking Start : DateT
Attention! many "returns": Customer::return(cr:car) Booking::Return:dateT Booking::returnCar()
End : DateT
Start<=End
Cat : CatET
car.notEmpty car.notEmpty implies Cat<=car.Cat
PickedUp : Boolean Return : DateT
create (cs:Customer,s:DateT,e:DateT (cs:Customer,s:DateT,e:DateT,ct:CatET):Booking ,ct:CatET):Booking
searchAvailCar():Car assignCar(cr:Car) returnCar()
6. Car Rental - Allowed Object Diagram: 3 Classes, 3 Objects Today="11/22" vw:Car
ada:Customer
LicenceNo="ABC123"
Name="Ada"
Cat=S customer
car
Registration booking
Assignment b:Booking Start="11/20" End="11/23"
Cat=E
PickedUp=true Return=undef
booking
6. Car Rental - Allowed Object Diagram: 3 Classes, 6 Objects b1:Booking
Today="11/22"
Start="11/20" End="11/23"
Cat=E
booking
PickedUp=true Return=undef
booking Assignment
Registration
car
customer
vw:Car
ada:Customer
LicenceNo="ABC123"
Name="Ada"
Cat=S customer
Registration booking
b2:Booking Start="11/16" End="11/18"
Cat=L bob:Customer
PickedUp=true Return="11/17"
Name="Bob"
ford:Car
LicenceNo="DEF456"
Cat=E
6. Car Rental - Disallowed Object Diagram b1:Booking
Today="11/23"
Start="11/20" End="11/23"
Cat=E
PickedUp=false Return=undef
booking Assignment car
ada:Customer
1. Booking b1 without customer 2. Car vw has 2 bookings 3. Booking b2 has 2 cars
Name="Ada"
LicenceNo="ABC123"
4. b2’s Cat is S, ford’s Cat is E
Cat=S
customer
vw:Car
car
Registration booking
Assignment b2:Booking
booking
Start="11/22" End="11/30"
Cat=S
PickedUp=true Return=undef
booking Assignment car
ford:Car
LicenceNo="DEF456"
Cat=E
6. Car Rental - Main Idea of Customer Statechart booked
book() create() cancel() noReturns
pickUp()
return()
mustReturn
6. Car Rental - Customer Statechart with Textual Details BOOK :
book(s,e,ct) [paramsOk] / createNewBooking createNewBooking cancel(b) [bookingBelongsToCustomer and bookingOpenOrDue bookingOpenOrDue and moreThanOneBookingForCustomer] moreThanOneBookingForCustomer] /
BOOK PICKUP :
pickUp(b) [bookingBelongsToCustomerAndIsDue] / findAvailableCarAndLinkBookingToFoundCar
recordCancelation booked
BOOK
create(n) / createNewCustomer
noReturns
cancel(b) [bookingBelongsToCustomer and bookingOpenOrDue and onlyOneBookingForCustomer] onlyOneBookingForCus tomer] / recordCancelation PICKUP
return(cr) [onlyOneCurrentBooking [onlyOneCurrentBookingForCustomer ForCustomer and noOpenDueBookingForCustome noOpenDueBookingForCustomerr and carBelongsToCustomer and carUnavailableOrDue] / handleBooking
return(cr) [onlyOneCurrentBookingForCustomer and existsOpenDueBookingForCustome existsOpenDueBookingForCustomerr and carBelongsToCustomer and carUnavailableOrDue] / handleBooking
mustReturn
return(cr) [moreThanOneCurrentBookingForCusto [moreThanOneCurrentBookingForCustomer mer and carBelongsToCustomer and carUnavailableOrDue] / handleBooking
PICKUP
BOOK
cancel(b) [bookingBelongsToCustomer and bookingOpenOrDue] / recordCancelation
6. Car Rental - Booking Statechart with Textual Details create(cs,s,e,ct) create(cs,s,e,ct) / createNewBooking customerCancels / open
recordCancelation
when(todayIsTheBookingsStartDay) when(todayIsAfterTheBookingStartDa when(todayIsAfterTheBookingStartDay) y) / recordCancelation due
closed
assignCar(cr) / linkBookingAndCarAndRecordPickUp
returnCar() / unlinkBookingAndCarAndRecordReturnDay current
6. Car Rental - Car Statechart with Textual Details
create(l,ct) / createNewCar available
carAssigned carReturned
unAvailable
carReturned
due
when(todayIsTheBookingsEndDay)
6. Car Rental - Customer Statechart with Fomal Details cancel(b) [ CANOK and CAN2booked ]
BOOK
( booking->select(open)->size booking->select(open)->size>0 >0 or booking->select(due)->size>0 booking->select(due)->size>0 ) and booking->select(current)->size=0
BOOK: book(s,e,ct) [ Today<=s and s<= e ] / booking.create(self,s,e,ct) PICKUP: pickUp(b) [ booking->includes(b) booking->includes(b) and b.due ] / result=b.searchAvailCar(); result=b.searchAvailCar(); b.assignCar(result) b.assignCar(result)
booked
CANOK: booking->includes(b) booking->includes(b) and (b.open or b.due) BOOK
CAN2noReturns: CAN2noReturns: booking->select(open booking->select(open or due)->size=1 create(n) /
cancel(b) [ CANOK and CAN2noReturns ]
CAN2booked: CAN2booked: booking->select(open booking->select(open or due)->size>1
Name=n
PICKUP
noReturns
RETOK: booking.car->includes(cr) booking.car->includes(cr) and (cr.unAvailable or cr.due)
return(cr) [ RETOK and RET2booked ] / booking->select(current)->size>0
RETACT BOOK
RET2noReturns: RET2noReturns: ( booking->select(open)->size booking->select(open)->size=0 =0 and booking->select(due)->size=0 booking->select(due)->size=0 ) and booking->select(current)->size=1 RET2booked: RET2booked: ( booking->select(open)->size> booking->select(open)->size>0 0 or booking->select(due)->size>0 booking->select(due)->size>0 ) and booking->select(current)->size=1
return(cr) [ RETOK and RET2noReturns ] /
RET2mustReturn: RET2mustReturn: booking->select(current)->size booking->select(current)->size>1 >1
RETACT mustReturn
RETACT: cr.booking.returnCar()
booking->select(open)->size=0 booking->select(open)->size=0 and booking->select(due)->size=0 booking->select(due)->size=0 and booking->select(current)->size=0
cancel(b) [ CANOK ]
return(cr) [ RETOK and RET2mustReturn ] / RETACT
PICKUP
6. Car Rental - Customer Statechart with Fomal Details Using Junction Points BOOK
( booking->select(open)->siz booking->select(open)->size>0 e>0 or booking->select(due)->siz booking->select(due)->size>0 e>0 ) and booking->select(current)->size=0
BOOK: book(s,e,ct) [ Today<=s Today<=s and s<= e ] / booking.create(self,s,e,ct) PICKUP: pickUp(b) [ booking->includes(b) and b.due ] / result=b.searchAvailCar(); b.assignCar(result)
booked
BOOK
[ CAN2booked ]
CANOK: booking->includes(b) and (b.open or b.due)
cancel(b) [ CANOK ]
CAN2noReturns: booking->select(open or due)->size=1 CAN2booked: booking->select(open or due)->size>1
create(n) / Name=n
[ CAN2noReturns ] RETOK: booking.car->includes(cr) and (cr.unAvailable or cr.due) [ RET2booked ]
noReturns
PICKUP
BOOK
[ RET2noReturns ]
RET2noReturns: RET2noReturns: ( booking->select(open)->siz booking->select(open)->size=0 e=0 and booking->select(due)->siz booking->select(due)->size=0 e=0 ) and booking->select(current)->size=1 RET2booked: ( booking->select(open)->size>0 or booking->select(due)->siz booking->select(due)->size>0 e>0 ) and booking->select(current)->size=1
return(cr) [ RETOK ] / RETACT
RET2mustReturn: RET2mustReturn: booking->select(current)->size booking->select(current)->size>1 >1 [ RET2mustReturn ]
mustReturn
RETACT: cr.booking.returnCar()
booking->select(open)->size=0 and booking->select(due)->size booking->select(due)->size=0 =0 and booking->select(current)->size=0
cancel(b) [ CANOK ]
booking->select(current)->size>0 PICKUP
6. Car Rental - Booking Statechart With Formal details create(cs,s,e,ct) / Start=s; End=e; Cat=ct; link(Registration,[cs,self])
open
when(Today=Start)
due
customer.cancel(self) / PickedUp=false
when(Today>Start) / PickedUp=false; customer.cancel(self)
assignCar(cr) / link(Assignment,[self,cr]); PickedUp=true
closed
returnCar() / unlink(Assignment,[self,car]); Return=Today current
6. Car Rental - Car Statechart with Formal Details
create(l,ct) / LicenceNo=l; Cat=ct available
booking.assignCar(self) booking.returnCar()
booking.returnCar()
unAvailable
due
when(Today=booking.End)
6. Car Rental - Sequence Diagram for Booking: Car.create; Booking.create :User
create("Ada")
ada:Customer
noReturns
create("ABC123",S)
vw:Car
available
book("11/20","11/23",E)
create(ada,"11/20","11/23",E)
b:Booking
booked
open
Today=b.Start
due
pickUp(b)
searchAvailCar() vw
assignCar(vw) unAvailable
current
vw
mustReturn
Today=b.End
due
return(vw)
returnCar() noReturns
available
closed
6. Car Rental - Sequence Diagram for Booking: Car.create; Booking.create Booking.create (with objects) objects) :User
create("Ada")
ada:Customer
ada:Customer
noReturns
create("ABC123",S)
ada:Customer
vw:Car
vw:Car
available
book("11/20","11/23",E)
create(ada,"11/20","11/23",E)
b:Booking
booked
ada:Customer
b:Booking
vw:Car
ada:Customer
b:Booking
vw:Car
ada:Customer
b:Booking
vw:Car
open
Today=b.Start
due
pickUp(b) searchAvailCar() vw
assignCar(vw) unAvailable
current
vw
mustReturn
Today=b.End
due
return(vw) returnCar() noReturns
available
closed
6. Car Rental - Collaboration Diagram for Booking: Car.create; Booking.create :User
1. create("Ada") 3. book("11/20","11/23",E)
2. create("ABC123",S)
4. pickUp(b) 5. return(vw)
customer
car
booking {new}
ada:Customer {new}
b:Booking {new}
3.1 create(ada,"11/20","11/23",E)
4.1 searchAvailCar()
4.2 assignCar(vw) 5.1 returnCar()
car {transient}
vw:Car {new}
6. Car Rental - Sequence Diagram for Booking: Booking.create; Booking.create; Car.create :User
create("Ada")
ada:Customer
noReturns
book("11/20","11/23",E) create(ada,"11/20","11/23",E) booked
b:Booking open
Today=b.Start
due
pickUp(b)
searchAvailCar() create("ABC123",S)
vw:Car
available
vw
assignCar(vw) unAvailable
current
vw
mustReturn
Today=b.End
due
return(vw)
returnCar() noReturns
available
closed
6. Car Rental - Sequence Diagram for Booking: Booking.create; Booking.create; Car.create (with objects) objects) :User
create("Ada")
ada:Customer
ada:Customer
noReturns
book("11/20","11/23",E) create(ada,"11/20","11/23",E) booked
b:Booking
ada:Customer
b:Booking
ada:Customer
b:Booking
vw:Car
ada:Customer
b:Booking
vw:Car
ada:Customer
b:Booking
vw:Car
open
Today=b.Start
due
pickUp(b) searchAvailCar() create("ABC123",S)
vw:Car
available
vw
assignCar(vw) unAvailable
current
vw
mustReturn
Today=b.End
due
return(vw)
returnCar() noReturns
available
closed
6. Car Rental - Collaboration Diagram for Booking: Booking.create; Booking.create; Car.create :User
1. create("Ada") 2. book("11/20","11/23",E)
3.2 create("ABC123",S)
3. pickUp(b) 4. return(vw) customer
car {transient}
booking {new}
ada:Customer {new}
b:Booking {new}
2.1 create(ada,"11/20","11/23",E)
3.1 searchAvailCar() 3.3 assignCar(vw) 4.1 returnCar()
car
vw:Car {new}
6. Car Rental - Sequence Diagram for Booking with Implicit Cancel :User
create("Ada")
ada:Customer
noReturns
book("11/20","11/23",E)
create(ada,"11/20","11/23",E) booked
b:Booking open
Today=b.Start
due
Today>b.Start cancel(b) noReturns
closed
6. Car Rental - Sequence Diagram for Booking with Explicit Cancel :User
create("Ada")
ada:Customer
noReturns
book("11/20","11/23",E)
create(ada,"11/20","11/23",E)
b:Booking
booked
open
noReturns
closed
cancel(b)
Today
6. Car Rental - Sequence Diagram for Booking with Early Return :User
create("Ada")
ada:Customer
noReturns
create("ABC123",S)
vw:Car
available
book("11/20","11/23",E)
create(ada,"11/20","11/23",E) booked
b:Booking open
Today=b.Start
due
pickUp(b)
searchAvailCar() vw
assignCar(vw) vw
unAvailable
current
available
closed
mustReturn
return(vw)
returnCar() noReturns
Today=b.End
6. Car Rental - Sequence Diagram for Booking with Late Return :User
create("Ada")
ada:Customer
noReturns
create("ABC123",S)
vw:Car
available
book("11/20","11/23",E)
create(ada,"11/20","11/23",E)
b:Booking
booked
open
Today=b.Start
due
pickUp(b)
searchAvailCar() vw
assignCar(vw) unAvailable
vw
current
mustReturn
Today>b.End
due
return(vw)
returnCar() noReturns
available
closed
6. Car Rental - Sequence Diagram for Two Bookings: b1.return; b2.assignCar
Today=b1.Start
vw:Car
b1:Booking
ada:Customer
b2:Booking
ford:Car
available
due
booked
open
available
assignCar(vw) unAvailable
Today=b1.End Today=b2.Start
mustReturn
current
due
due
return(vw) available
closed
assignCar(ford)
current
unAvailable
6. Car Rental - Sequence Diagram for Two Bookings: b2.assignCar; b2.assignCar; b1.return
Today=b1.Start
vw:Car
b1:Booking
ada:Customer
b2:Booking
ford:Car
available
due
booked
open
available
assignCar(vw) unAvailable
Today=b1.End Today=b2.Start
mustReturn
current
due
due
assignCar(ford) current
return(vw) available
closed
unAvailable
6. Car Rental - Activity Diagrams for pickUp: Textual Level and Operation Level ustomer::p c
p
: ar
ustomer::p c
p
: ar
testAvailableCars
[noCarAvailable]
[carAvailable]
result=b.searchAvailCar() chooseAnAvailableCar
purchaseANewCar
connectTheBookin connectT heBookingT gToTheCar b.assignCar(result) indicateThatACarHasBeenPickedUp
returnTheCar
return(result)
6. Car Rental - Activity Diagrams for pickUp: Statement Level and Formal Level Customer::pickUp(b):Car
Customer::pickUp(b):Car
Car.allInstances->exists(cr| cr.available and cr.Cat>=b.Cat)
testAvailableCars
[else]
[carAvailable]
[true]
[false]
result:=Car.allInstances-> result=someAvailableCar
result=someNewCar
select(cr|cr.available select(cr|cr.available and cr.Cat>=b.Cat)->any
result:=Car.create(newLicN result:=Car.create(newLicNo,b.Cat) o,b.Cat)
link(Assignment,[b,result])
b.car:=b.car->including(result)
b.pickedUp=true
b.pickedUp:=true
return(result)
return(result)
6. Car Rental - Developing a Consistent Model
develop object diagrams
develop sequence diagrams
develop class diagram
develop statechart diagrams
[diagrams inconsistent or incomplete]
[more diagrams needed]
[diagrams ok]
modify object diagram
modify class diagram
modify statechart diagram
modify sequence diagram
develop more sequence diagrams
develop more object diagrams
6. Car Rental - Details for Diagram Consistency From class diagram to object diagrams - for each class there is at least one object diagram with an object of that class - for each attribute and role name there is at least one object diagram with an object with that attribute and role name From class diagram to sequence diagrams - for each class there is at least one sequence diagram with an object of that class - for each operation there is at least one sequence diagram with that operation as a message From class diagram to statechart diagrams - for each attribute there is at least one operation that modifies that attribute in some statechart - for each operation there is at least one statechart where that operation occurs as a call evant or as a call action From statechart diagrams to class diagram - each call event refers to an operation in a class - each attribute and role name occurring in a guard refers to an attribute in a class and a role name of a class - each call action, assignment action, and link/unlink action refers to an operation, attribute, and role name in a class From object diagrams to class diagram - each class of an object occurs as as class
OD
- each attribute and role name refers to an attribute in a class and a role name of a class
From sequence diagram to class diagram - each object refers to a class - each message refers to an operation in a class From sequence diagram to statechart diagram - each state refers to a state in the statechart diagram - each message sequence is allowed by at least one statechart event and action order - each state sequence is allowed by at least one state sequence order
CD
SC
From statechart diagram to the sequence diagram - each call action completely occurs in the sequence diagram (all sub-actions from the call action occur)
SeqD