class diagram. classes software design (uml) class name attributes operations a class is a...
TRANSCRIPT
![Page 1: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/1.jpg)
Class Diagram
![Page 2: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/2.jpg)
Classes
Software Design (UML)
Class Name
attributes
operations
A class is a description of a set of objects that share the same attributes,operations, relationships, and semantics.
Graphically, a class is rendered as a rectangle, usually including its name,attributes, and operations in separate,designated compartments.
![Page 3: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/3.jpg)
Class Names
Software Design (UML)
ClassName
attributes
operations
The name of the class is the only required tag in the graphical representation of a class. It always appears in the top-most compartment.
![Page 4: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/4.jpg)
Class Attributes
Software Design (UML)
Person
name : Stringaddress : Addressbirthdate : Datessn : Id
An attribute is a named property of a class that describes the object being modeled.In the class diagram, attributes appear in the second compartment just below the name-compartment.
![Page 5: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/5.jpg)
Class Attributes (Cont’d)
Software Design (UML)
Person
name : Stringaddress : Addressbirthdate : Date/ age : Datessn : Id
Attributes are usually listed in the form:
attributeName : Type
A derived attribute is one that can becomputed from other attributes, butdoesn’t actually exist. For example,a Person’s age can be computed from his birth date. A derived attribute is designated by a preceding ‘/’ as in:
/ age : Date
![Page 6: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/6.jpg)
Class Attributes (Cont’d)
Software Design (UML)
Person
+ name : String# address : Address# birthdate : Date/ age : Date- ssn : Id
Attributes can be:+ public# protected- private/ derived
![Page 7: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/7.jpg)
Class Operations
Software Design (UML)
Person
name : Stringaddress : Addressbirthdate : Datessn : Id
eatsleepworkplay
Operations describe the class behavior and appear in the third compartment.
![Page 8: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/8.jpg)
Class Operations (Cont’d)
Software Design (UML)
PhoneBook
newEntry (n : Name, a : Address, p : PhoneNumber, d : Description)getPhone ( n : Name, a : Address) : PhoneNumber
You can specify an operation by stating its signature: listing the name, type, and default value of all parameters, and, in the case of functions, a return type.
![Page 9: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/9.jpg)
Depicting Classes
Software Design (UML)
Person
name : Stringbirthdate : Datessn : Id
eat()sleep()work()play()
When drawing a class, you needn’t show attributes and operation in every diagram.
Person
nameaddress
birthdate
Person
eatplay
Person
![Page 10: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/10.jpg)
Relationships
Software Design (UML)
In UML, object interconnections (logical or physical), are modeled as relationships.
There are three kinds of relationships in UML:
• dependencies
• generalizations
• associations
![Page 11: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/11.jpg)
Dependency Relationships
Software Design (UML)
CourseSchedule
add(c : Course)remove(c : Course)
Course
A dependency indicates a semantic relationship between two ormore elements. The dependency from CourseSchedule to Course exists because Course is used in both the add and remove operations of CourseSchedule.
![Page 12: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/12.jpg)
Generalization Relationships
Software Design (UML)
PersonA generalization connects a subclassto its superclass. It denotes an inheritance of attributes and behaviorfrom the superclass to the subclass andindicates a specialization in the subclassof the more general superclass.
Student
![Page 13: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/13.jpg)
Generalization Relationships (Cont’d)
Software Design (UML)
Student
UML permits a class to inherit from multiple superclasses, although some programming languages (e.g., Java) do not permit multiple inheritance.
TeachingAssistant
Employee
![Page 14: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/14.jpg)
Association Relationships
Software Design (UML)
If two classes in a model need to communicate with each other, there must be link between them.
An association denotes that link.
InstructorStudent
![Page 15: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/15.jpg)
Association Relationships (Cont’d)
Software Design (UML)
We can indicate the multiplicity of an association by adding multiplicity adornments to the line denoting the association.
The example indicates that a Student has one or more Instructors:
InstructorStudent1..*
![Page 16: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/16.jpg)
Association Relationships (Cont’d)
Software Design (UML)
The example indicates that every Instructor has one or more Students:
InstructorStudent1..*
![Page 17: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/17.jpg)
Association Relationships (Cont’d)
Software Design (UML)
We can also indicate the behavior of an object in an association (i.e., the role of an object) using rolenames.
InstructorStudent1..*1..*
learns fromteaches
![Page 18: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/18.jpg)
Association Relationships (Cont’d)
Software Design (UML)
We can also name the association.
TeamStudentmembership
1..* 1..*
![Page 19: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/19.jpg)
Association Relationships (Cont’d)
Software Design (UML)
We can specify dual associations.
TeamStudent
member of
1..*
president of1 1..*
1..*
![Page 20: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/20.jpg)
Association Relationships (Cont’d)
Software Design (UML)
We can constrain the association relationship by defining the navigability of the association. Here, a Router object requests services from a DNS object by sending messages to (invoking the operations of) the server. The direction of the association indicates that the server has no knowledge of the Router.
Router DomainNameServer
![Page 21: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/21.jpg)
Association Relationships (Cont’d)
Software Design (UML)
Associations can also be objects themselves, called link classes or an association classes.
WarrantyProduct
Registration
modelNumberserialNumberwarrentyCode
![Page 22: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/22.jpg)
Association Relationships (Cont’d)
Software Design (UML)
We can model objects that contain other objects by way of special associations called aggregations and compositions.
An aggregation specifies a whole-part relationship between an aggregate (a whole) and a constituent part, where the part can exist independently from the aggregate. Aggregations are denoted by a hollow-diamond adornment on the association.
CarEngine
Transmission
![Page 23: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/23.jpg)
Association Relationships (Cont’d)
Software Design (UML)
A composition indicates a strong ownership and coincident lifetime of parts by the whole (i.e., they live and die as a whole). Compositions are denoted by a filled-diamond adornment on the association.
Window
Scrollbar
Titlebar
Menu
1
1
1
1
1
1 .. *
![Page 24: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/24.jpg)
Interfaces
Software Design (UML)
An interface is a named set of operations that specifies the behavior of objects without showing their inner structure. It can be rendered in the model by a one- or two-compartment rectangle, with the stereotype <<interface>> above the interface name.
<<interface>>ControlPanel
![Page 25: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/25.jpg)
Interface Services
Software Design (UML)
Interfaces do not get instantiated. They have no attributes or state. Rather, they specify the services offered by a related class.
<<interface>>ControlPanel
getChoices : Choice[]makeChoice (c : Choice)getSelection : Selection
![Page 26: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/26.jpg)
Interface Realization Relationship
Software Design (UML)
<<interface>>ControlPanel
VendingMachine
A realization relationship connects a class with an interface that supplies its behavioral specification. It is rendered by a dashed line with a hollow triangle towards the specifier.
specifier
implementation
![Page 27: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/27.jpg)
Interfaces
Software Design (UML)
A class’ interface can also be rendered by a circle connected to a class by a solid line.
File
outputStream
inputStream
FileWriter{file must not be locked}
FileReader{file must exist}
![Page 28: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/28.jpg)
Packages
Software Design (UML)
Compiler
A package is a container-like element for organizing other elements into groups.
A package can contain classes and other packages and diagrams.
Packages can be used to provide controlled access between classes in different packages.
![Page 29: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/29.jpg)
Packages (Cont’d)
Software Design (UML)
Classes in the FrontEnd package and classes in the BackEnd package cannot access each other in this diagram.
FrontEnd BackEnd
Compiler
![Page 30: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/30.jpg)
Packages (Cont’d)
Software Design (UML)
Classes in the BackEnd package now have access to the classes in the FrontEnd package.
FrontEnd BackEnd
Compiler
![Page 31: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/31.jpg)
Packages (Cont’d)
Software Design (UML)
JavaCompiler
We can model generalizations and dependencies between packages.Compiler
Java
![Page 32: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/32.jpg)
Star UML: Entity-Control-Boundary Pattern
Software Design (UML)
Entity-Control-Boundary Pattern is a simplification of the Model-View-Controller Pattern
![Page 33: Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,](https://reader035.vdocuments.us/reader035/viewer/2022062304/56649f285503460f94c4026c/html5/thumbnails/33.jpg)
Star UML: Entity-Control-Boundary Pattern
Software Design (UML)
1.Actors can only talk to boundary objects.2.Boundary objects can only talk to controllers and actors.3.Entity objects can only talk to controllers.4.Controllers can talk to boundary objects and entity objects, and to other controllers, but not to actors