210 likes | 226 Views
This article explains how to identify classes in use cases by looking for nouns and noun phrases that describe the nature or structure of information in the application. It also provides examples of attribute and operation declarations.
E N D
classes • a class describes a group of objects with: • similar properties (attributes) • common behavior • common relationships to other objects • common meaning class diagramsshow classes with their attributes and operations, together with the associations between classes
what might be a class? inventory system replenishment sale supplier stock clerk loading dock item for sale purchase order storage pattern physical count scanner stale dating airline reservation system reservation arrival travel agency customer travel office aircraft reservation flight timetable reservation transaction index reservation cancellation concept event organization person place physical item business concept logical entity application computer behavior
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)
describing a class unique simple name or path name (if it’s in a package) named property describing the range of values instances may hold optional behaviors the class can exhibit contract or obligation the class may have
class name name of object simple name e.g. order, customer, campaign path name e.g. business rules::FraudAgent, java::awt::Rectangle client order +OrderForm +TrackingForm -Order A package is a general purpose mechanism for organizing elements (in this case classes) into groups
attributes Wall + material : string + height : Float + width : Float attributes + thinkness : Float + isLoadBearing : Boolean = false - density : Float + dateBuilt : Date + public = can access from other classes - private = cannot access from other classes # protected = can access from subclasses
attribute declaration [visibility] name [multiplicity] [: type] [= initial-value] [{property-string}] visibility name multiplicity type initial-value property-string + (public), # (protected), - (private) e.g. CustomerName, DiscountRate e.g. [0..1], [2..*] e.g. Point, String, Date, etc. e.g. =(0,0), = null changeable (default), addOnly, frozen 6 examples of legal attribute declarations origin 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.
operations operations Patient + makeAppointment ( ) + calculateLastVisit ( ) • examples of operations • change the value of attributes • change state • change links • invoke other objects + changeStatus ( ) + provideMedicalHistory ( ) + public # protected - private ( ) operation parameter
operation signatures [visibility] name [(parameter-list)] [ : return-type] visibility name parameter-list return-type + (public), # (protected), - (private) e.g. restart, addStudent see below e.g. Integer, String, etc each parameter looks like this [direction] name : type [= default-value] direction name type default-value in, out, inout e.g. getId, calculateBonus Boolean, Money, etc. e.g. 42, John
an example Campaign title : String campaignStartDate : Date campaignFinishDate : Date estimatedCost : Money actualCost : Money completionDate : Date datePaid : Date completed (completionDate : Date, actualCost: Money) parameters in signatures setFinishDate ( FinishDate : Date) recordPayment ( datePaid : Date ) returned value costDifference ( ) : Money
salesStaff client sales staff liaises with 0..* 1 staffPosition staffMember is allocated to 0..* 1..* memberPosition
links 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
CLASS NAME RESPONSIBILITIES COLLABORATING CLASSES operation 1 operation 2 operation 3 etc. class A none class B, class C CRC cards Class-Responsibility-Collaboration cards
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 exceptions basic flow