230 likes | 348 Views
UML Class Diagram. and a little about Object Diagrams. Class. Association. Business processes (in Activity Diagram). Communication between people (in Sequence Diagram. Business concepts (in Class Diagram). Use case. Activity Diagram. Sequens Diagram. Information Model
E N D
UML Class Diagram and a little about Object Diagrams Class Association
Business processes (in Activity Diagram) Communication between people(in Sequence Diagram Business concepts (in Class Diagram) Use case Activity Diagram Sequens Diagram Information Model (in Class Diagram) The reality and UML-models The reality UML-models
Student Course personalnr name email courseID courseName registerForCourse() Class Diagrams – central in UML TheClassDiagramsarethemajority–havealmostbecomesynonymouswithUML. ClassDiagramsdescribesClassesinadomainorinasystem,andstaticassociationsbetweentheclasses. ClassDiagramsalsoshowstheattributesandoperationsoftheclasses. • Note that following words have been used as synonymes: • type och class, • relation och association, • structural och static. • In UML-context we should use the concepts marked in bold letters.
Classes – UML-notation • The UML-notation for a class is a rectangle with (normally) three sections or compartments. • the compartment at the top contains the name of the class in bold letters and a capital first letter. • the compartment in the middle contains the names of the attributes in the class. • the compartment at the bottom contains the names of the operations in the class. Student Note the way to write the names of the attributes and operations – yet a convention and no formal rules: - begins with a small letter, a capital letter can be placed in the middle if it consists of several words. - name of the class and –names of the attributes are written as substantives or substantive phrases, names of classes begin with a capital letter. - operations are written as verbs, also note the parentheses after the operation name. personalnr name email registerForCourse()
Student Student Student personalnr name email personalnr name email registerForCourse() requestIncreasedAccount() Classes – variants of notations Class name Operations Attributes
Student personalnr name email registerForCourse() requestIncreasedAccount() Classes – objects, attributes & methods Objects: Studentscanhavealotofsimilarities,forexamplee-mail,andtheycanregisterforcourses. WecollectsimilaritiesandcreatetheclassStudent.EverystudentisnowanobjectoftheclassStudent. AllStudentobjectshaveavalueontheattributesandareabletoperformthemethods. Attributes:are used to describe static characteristics within a class. Are given values in their objects. Operations:are spoken about at class level when to represent the dynamic behaviors of the objects. Operations are called methods at the object level.
Class Diagram and Object Diagram Class Object (instance) Object (instance) annaSvan:Student nilsHall:Student Student personalnr = ”770102-XXXX” name = ”Anna Cecilia Svan” address = ”Ekvägen 10” email = ”sva@dsv.su.se” personalnr name address email personalnr = ”850302-XXXX” name = ”Nils Erik Hall” address = ”Rågstigen 3” email = ”hal@dsv.su.se” Class Diagram Object Diagram Often called Instance Diagram. Increased notation för naming. Attributes gets values. All associationes from the Clas Diagram follows to the objects. Can be seen as a snapshot of one or more objects at a certain moment. Why? The values of the attributes can be changed during the lifecycle of the objects.
Attributes & associations are properties Properties Associations Student Registration Course personalnr name email registrationID date courseID courseName Attributes Properties • Properties (characteristics) • is UML’s umbrella term for the attributes and associations of classes. • models the static (structural) characteristics of classes.
Properties have multiplicity Student Registration Course 1..1 0..* 0..* 1..1 personalnr name email [1..1] registrationID date [1..1] [1..1] courseID courseName [1..1] [1..1] [0..1] [1..*] Themultiplicityforaproperty(attributeorassociation)indicateshowmanydifferentobjects(orvalues)thatareabletofulfiltheproperty. Multiplicityforassociationsisstatedateachassoiciatedclass. Thecompletewaytowritemultiplicity,isthat: -thesmallestnumberisstatedfirst, -thelargestnumberisstatedlast, -twodotsarewrittenbetweenthenumbers.
Multiplicity – usual combinations Course Student Registration 0..* 1..1 0..* 1..1 personalnr name email [1..1] registrationID date [1..1] [1..1] courseID courseName [1..1] [1..1] [0..1] [1..*] 1..1Minimum1andmaximum1.Example:Astudenthasone,andonlyone,valueattheattributepersonalnr. 1..*Minimum1andaninfiniteuppernumber.Example:Astudentisalwaysgivenonee-mailaddress,butcanhavemanymoree-mails. 0..*0isvalidandaninfiniteuppernumber.Example:Astudentdoesnothavetoberegisteredonacourse,butcanberegisteredonmanycourses. 0..10isvalidandmaximum1.Example:Acoursedoesnotneedtohavebeengivenanameandcanpossiblyhaveonename.
Multiplicity for associations Student Registration Course 0..* 1..1 0..* 1..1 personalnr name email registrationID date courseID courseName multiplicitydescribeshowmanydifferentobjectsthatcanbepartofanassociationbetweentwoclasses. Exemple: AStudentobjectisassociatedtozero-to-manyRegistrations. ARegistrationobjectisassociatedtoone-to-one,i.e.exactlyone,Student.
More about multiplicity for associations Registration Student Course 1..1 0..* 0..* 1..1 anna:Student oop:Course 9:Registration nils:Student 2:Registration oos:Course 6:Registration tove:Student jök:Course
Multiplicity of associations with Venn-diagram Student Registration Course 9 oop Anna 2 oos Nils 6 jök Tove
Notes • Notes is comments in UML-diagrams. • Not connected to any special modelling element • If notes is about a special modelling element it is connected to the element with a broken line. Note that the line ends with a small unfilled circle. • Notes can also be used to state constraints for the modelling element. The constraints then have to be written within curly braces. Constraints can also be written in text or more formally. Includes University students, but not secondary school students. { Only students living at IP } Student
Anställd + companynr: Integer [1..1] = 4222 {readOnly} Attribute - notation visibility name type multiplicity = default value {property} The only mandatory part in the notation of the attribute. The data typeof the value. Limits which type of values the attributes can have. Multiplicity Perhaps furtherproperties of the attribute. Automaticly assignedwhen an object is created. There are publik (+), privat (-), protected (#) visibility, and packet visibility (~).
Employee + companynr: Integer [1..1] = 4222 {readOnly} + getNamn (employeenr:Integer): String Operationes - notation visibility name (parameter list) : return type {property} The only mandatory part in the notation of the operation. List of the parameters used by the operation. It can be input (in), output (out), or both (inout). The data type of the returnedvalue. Perhaps furtherproperties of the operation. There are publik (+), privat (-), protected (#) visibility, and packet visibility (~).
UML-concept feature Features Static features Dynamic features properties Operations Attribute Associations
To name associations Threewaystonameassociations: 1)withaverbateachclass. Teacher Student 0..* is supervised employeenr [1..1]] studregnr [1..1] is supervising 1..*
To name associations Three ways to name associations:2) Only one verb at the association line . Teacher Student 0..* supervise employeenr [1..1] studregnr [1..1] 1..1
To name associations Three ways to name associations: 3) With a substantive at each class. Teacher supervisor Student 0..* thesiswriter employeenr [1..1] studregnr [1..1] 1..*
Class Diagram – a summary Classes Attributes Registration Student Associations personalnr name email [1..1] registrationID date [1..1] [1..1] [1..1] 1..1 0..* [1..*] Operations registerForCourse() listRegistrations() Multiplicity Includes University students, but not secondary school students. . Notes annaSvan: Student personalnr = ”770102-XXXX” name = ”Anna Cecilia Svan” email = ”sva@dsv.su.se” Objects registerForCourse()