Skip to main content
Unified Modeling Language
(UML)
Class and object Diagrams
ITCS 114
Classes in UML
• 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.
ClassName
attributes
operations
ITCS 114
Class Names
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.
ClassName
attributes
operations
ITCS 114
Class Attributes
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.
Attributes are usually listed in the form:
attributeName : Type
Person
name : String
ID : long
ITCS 114
Class Attributes (Cont’d)
Person
- name : String
- ID : Long
Attributes can be:
+ public
- private
ITCS 114
Class Operations
Person
- name : String
- ID : Long
setPerson
getName
getID
Operations describe the class behavior
and appear in the third compartment.
ITCS 114
• 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.
• Constructors should not be included in
UML class diagram
Class Operations (Cont’d)
Person
- name : String
- ID : Long
+setPerson( String, Long): void
+getName( ) : String
+getID( ): Long
ITCS 114
UML Objects (instances)
• Specify object (instance)
name and the class name
• For each attribute show its
value
• Do not show methods
Employee: Person
name = “Eman”
ID = 589651
Object name: Class Name
Attribute name= value
Student: Person
name = “Ahmed”
ID = 123456
Examples of Objects of type Person
Person
- name : String
- ID : Long
+setPerson( String, Long): void
+getName( ) : String
+getID( ): Long
Class
ITCS 114
Exercise- Book
Design a class to represent a book. Think about the attributes of a
book; that is, what data is in the book? What behaviours might be
reasonable for a book? Use the answers to these questions to write a
UML class diagram for a book class. Then give two examples of
instances of this class.
ITCS 114
Exercise- Book
Book
- title: String
- authorName: String
- publisher: String
- numCopies: int
+setBook( String, Long, int): void
+setTitle(String): void
+setAuthor(String): void
+setPublisher(String): void
+incrementNumCopies(int): void
+getName( ) : String
+getID( ): Long
+getNumCopies: int
JavaBook: Book
Title “= Java Book”
authorName = “Smith”
Publisher = “Springer”
numCopies = 100
C++Book: Book
Title = “Introduction to C++”
authorName = “Han”
Publisher = “Elsevier”
numCopies = 25
Examples of Objects of type Book
Book UML Class
ITCS 114
Exercise- Rectangle
Design a class to represent a Rectangle. Think about the attributes and
methods of a rectangle? Use the answers to these questions to write a
UML class diagram. Then give two examples of instances of this class.
ITCS 114
Exercise- Rectangle
Rectangle
- Width: double
- Length: double
+setR( double, double): void
+getWidth( ) : double
+getLength( ): double
+getArea: double
R1: Rectangle
Width = 25.5
Length = 34.75
R2: Rectangle
Width = 100
Length = 200
Examples of Objects of type Rectangle
Rectangle UML Class
ITCS 114
Test- Question
Question 4 ( 6 points)
Design a class to represent a Product. The main attributes of this class
are: Name, Price and Code. Draw a UML class diagram with the given
attributes and suitable methods. Then show one instance of this class.
ITCS 114
Test – Question –
Answer
Product UML Class
An Object Example of type Product