University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 1 classes a class...
-
Upload
ralf-barton -
Category
Documents
-
view
214 -
download
0
Transcript of University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 1 classes a class...
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 1
classes
a class describes a group of objects with:• similar properties (attributes)• common behavior• common relationships to other objects• common meaning
class diagrams show classes with their attributes and operations, together with the associations between classes
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 2
what might be a class?
concepteventorganizationpersonplacephysical itembusiness conceptlogical entityapplicationcomputerbehavior
inventory systemreplenishmentsalesupplierstock clerkloading dockitem for salepurchase orderstorage patternphysical countscannerstale dating
airline reservation systemreservationarrivaltravel agencycustomertravel officeaircraftreservationflight timetablereservation transactionindexreservation cancellation
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 3
finding classes in use cases
• look for nouns and noun phrases in the description of the use cases
• include them in the model if they explain the nature or structure of information in the application
• but don’t create concepts which:• are beyond the scope of the system• refer to the system as a whole• duplicate other classes• are too vague or specific (few instances)
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 4
describing a class
name of object
responsibilities
operations
attributes
unique simple name or path name (if it’s in a
package)
named property describing the range of
values instances may hold
behaviors the class can exhibit
contract or obligation the class may have
op
tion
al
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 5
class namename of object
responsibilities
operations
attributes
name of object
simple name e.g. order, customer, campaignpath name e.g. business rules::FraudAgent,
java::awt::Rectangle
A package is a general purpose mechanism for organizing elements (in this case classes) into groups
client order
+OrderForm+TrackingForm-Order
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 6
attributesname of object
responsibilities
operations
attributesattributes
+ public = can access from other classes- private = cannot access from other classes# protected = can access from subclasses
Wall
+ material : string+ height : Float+ width : Float+ thinkness : Float+ isLoadBearing : Boolean = false- density : Float+ dateBuilt : Date
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 7
[visibility] name [multiplicity] [: type] [= initial-value] [{property-string}]
visibilityname
multiplicitytype
initial-valueproperty-string
+ (public), # (protected), - (private)e.g. CustomerName, DiscountRatee.g. [0..1], [2..*]e.g. Point, String, Date, etc.e.g. =(0,0), = nullchangeable (default), addOnly, frozen
6 examples of legal attribute declarationsorigin origin : Point = (0,0)+ origin id : integer {frozen}origin : Point name : [0..1] : String
Booch, jacobson, Rumbaugh. The Unified Modeling Language User Guide. Addison Wesley. 1999. pg 127-128.
attribute declaration
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 8
operationsname of object
responsibilities
operations
attributes
operations
+ public # protected - private
( ) operation parameter
Patient
+ makeAppointment ( )
+ calculateLastVisit ( )
+ changeStatus ( )
+ provideMedicalHistory ( )
examples of operations • change the value of attributes• change state• change links• invoke other objects
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 9
operation signatures
[visibility] name [(parameter-list)] [ : return-type]
visibilityname
parameter-listreturn-type
+ (public), # (protected), - (private)e.g. restart, addStudentsee belowe.g. Integer, String, etc
each parameter looks like this[direction] name : type [= default-value]
directionnametype
default-value
in, out, inoute.g. getId, calculateBonusBoolean, Money, etc.e.g. 42, John
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 10
an example
parameters in signatures
returned value
Campaign
title : String
campaignStartDate : Date
campaignFinishDate : Date
estimatedCost : Money
actualCost : Money
completionDate : Date
datePaid : Date
completed (completionDate : Date,
actualCost: Money)
setFinishDate ( FinishDate : Date)
recordPayment ( datePaid : Date )
costDifference ( ) : Money
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 11
classes and instances
instance of a class
FoodCO:client
companyAddress= Evans Farm, NorfolkcompanyName=FoodCocompanyTelephone=4165551212
:client
anonymous instance of a class
(used in collaboration diagrams)
class
client
companyAddresscompanyNamecompanyTelephone
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 12
subclass 1
attributesspecific to this
subclass
subclass 2
attributesspecific to this
subclass
subclass 3
attributesspecific to this
subclass
superclass
attributes sharedby all subclasses
( denotes generalization )
classes and subclasses
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 13
types of classes
<<entity>>campaign
titlecampaignStartDatecampaignFinishDate
getCampaignAdvert()addNewAdvert()
boundary class entity class control class
<<control>>control::addAdvert
showClientCampaigns()showCampaignAdverts()createNewAdvert()
<<boundary>>user interface::AddAdvert
startInterface()assignStaff()selectClient()selectCampaign()
entityboundary control
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 14
salesStaff clientsales staff
liaises with1 0..*
staffPosition staffMemberis allocated to
1..* 0..*
memberPosition
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 15
links
FoodCO:client World Tradition:campaign
FoodCo is the client in the World Tradition campaign
and associations
staff members are assigned client(s)each client has one staff assigned to it
staffMember
staffNamestaffNostaffStartDate
client
companyNamecompanyAddressliaises with
1 0..*
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 16
class diagram
<<boundary>>user interface::assignStaff
startInterface()assignStaff()selectClient()selectCampaign()
<<control>>control::assignStaff
assignStaff()getClientCampaign()showCampaignStaff()
<<entity>>client
companyNamecompanyAddresscompanyTelephone
getClientCampaign()getClients()
<<entity>>campaign
titlecampagnStartDatecampaignFinishDate
getCampaignStaff()assignStaff()
<<entity>>staffMember
staffNo()staffName()staffStartDate()
getStaff()assignStaff()getStaffDetails()
1 assigned to 0..*1 places 0..*
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 17
booking
roomTypeAvailability : Integer
reserveAccomodation (date, duration, roomType, guestName)freeAccommodation (date, duration, roomType)getAvailable (date, duration, roomType)decreaseAvailability (date, duration, roomType)confirmReservation (reservationNumber)fillReservation(reservation)checkInGuest (guestName)cancelReservation (reservationNumber)showReservation (startDate, reservationState)showAvailability (date, duration, roomType)showRoomRate (roomType)showReservation (reservationNumber)showRoomDirections (room)
room
roomTypeAvailability :Integer
occupy (guestName)findVacant (roomType)
guest
name:Stringaddress : StringcarRegNumber: String
reservation
status: Integerdate: Dateduration: IntegerroomType: Integer
create (startDate, duration, roomType, customerName)makProvisionalConfirmExercisecancelcalculatePrice (discountPercent)getDetails (startDate, Duration, roomType, customerName)allocateCustomer (customerRef)allocateRoom (roomNumber, guestName)
customername: Stringaddress: StringpercentageDsicount::Integer
findDiscount()
1
1..*
1..*1
1
1..*
0..*1
class diagram
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 18
class diagram
takes
*
required_for
required_by
*
0..* 0..*
11
<<entity>>student
<<PK>>student_id:Stringstudent_name:Stringcurrent_fees:Money
areYouValid(out s_check)addCourse(crsoffOID)feesPaid(out paid)
<<boundary>>user interface::ProgramEntryWindow
add(std, crs, sem)destroy()
<<entity>>prereqCourse
prereq_grade : String
prereq(out crsOID)
<<entity>>academicRecord
course_code : Stringyear : datesemester : Integergrade : String
prereqsSatisfied(out satisfied)
<<entity>>grade
grade : Stringmark : set<Nmber>
<<entity>>courseOffering
year : Datesemester : Integerenrolment_quota: I nteger
areYouOpen(out c_check)addStudent(stdOID)
<<entity>>course
<<PK>>course_code : Stringcourse_name : Stringcredit_points : Integer
areYouOpen(out c_check)preseq(out crs)addStudent(stdOID)
*
*
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 19
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 20
Class-Responsibility-Collaboration cards
CLASS NAME
RESPONSIBILITIES COLLABORATING CLASSES
operation 1operation 2operation 3etc.
class Anoneclass B, class C
CRC cards
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 classes 21
actor action
1.0 enter customerNumber
2.0 enter itemCode
3.0 enter itemQuantity
4.0 indicate order is complete
E1.0 enter customerNumber
E1.1 select addCustomer
system response
display customerName
display itemDescription
display itemPrice
display orderAmount and orderNumber
display “not found” message
offer selection of exit or add customer
invoke addCustomer
excep
tion
s
basic
flow