Class Diagram: Helping Material

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 32

Class Diagram

Helping Material
Class Diagram
• In software engineering, a class diagram in the Unified Modeling
Language (UML) is a type of static structure diagram that describes
the structure of a system by showing the system's classes, their
attributes, operations (or methods), and the relationships among
objects.
Class Diagram
• Class diagram represents the static view of an application. Class
diagram is not only used for visualizing, describing, and documenting
different aspects of a system but also for constructing executable
code of the software application.
• Class diagram describes the attributes and operations of a class and
the constraints imposed on the system. The class diagrams are widely
used in the modeling of object-oriented systems because they are the
only UML diagrams, which can be mapped directly with object-
oriented languages.
Constraint
What is a Class?
• A general template that we use to create specific instances or
objects in the application domain
• Represents a kind of person, place, or thing about which the system
will need to capture and store information
UML Representation of Class
Example of a Class Diagram
Video Rental System
visibility multiplicity class name

Customer 1..* 1..*


Video
-CID: int -cassetteID : int
-name: String rents -cassetteVolumeNo: int
+rentMovie()
+authenticateCustomer ()

attributes methods
relationship
Attributes in a Class
• Properties of the class about which we want to capture information
• Represents a piece of information that is relevant to the description of the class within the
application domain
• Contains information that the analyst or user feels that the system should store
• Represents properties that describe the state of the object
• Only attributes important to the task should be included in the class
• For example, for employee, employee name is a good attribute; employee hair color is not
(not relevant in the business application)
Attributes in a Class
• Only add attributes that are primitive or atomic types
• Derived attribute
• attributes that are calculated or derived from other
attributes
• denoted by placing slash (/) before name
Attributes in a class

• One word attribute name in lower case letter


• If word contain more than one word the words are join and each
word other then first is written in upper case
Attributes in a class
Visibility of Attributes and Operations
• Visibility in a class diagram
• Shown on attributes and methods
1) Public
• One that is not hidden from any other object
• Default visibility for a method
2) Protected
• One that is hidden from all other classes except its immediate subclasses
3) Private
• One that is hidden from all other classes
• Default visibility for an attribute
Visibility of Attributes and
Operations
Visibility Symbol Accessible To
Public + All objects within your system.

Protected # Instances of the implementing class and its


subclasses.

Private - Instances of the implementing class.


 
Operations in a Class
• Represents the actions or functions that a class can perform
• Describes the actions to which the instances of the class will be
capable of responding
Class Operations

Person

name : String
address : Address
birthdate : Date
ssn : Id
eat Operations describe the class behavior
sleep and appear in the third compartment.
work
play
Class Responsibilities

A class may also include its responsibilities in a class diagram.

A responsibility is a contract or obligation of a class to perform


a particular service.
SmokeAlarm

Responsibilities

-- sound alert and notify guard station


when smoke is detected.

-- indicate batteryDesign
Software state (UML)
Relationships among Classes
• Represents a connection between multiple classes or a class and itself
• Generalization
• Composition
• Aggregation
Generalization
• A taxonomic relationship between a more general classifier and a
more specific classifier
• Enables the analyst to create classes that inherit attributes and
operations of other classes
• Represented by a-kind-of relationship
• Super class, Sub Class
Generalization Relationship
Person

Employee Customer

Manager Engineer
Generalization Relationship
Employee
hireDate
Generalization

receivePay
performWork

Manager Engineer
department certifications
bonus
hireEmployee analyze
promoteEmployee design
Specialization
Generalization Relationship
• Superclass
• Employee class
• Generalization that contains attributes and operations common to all subclasses
• Subclass
• Manger and Engineer classes
• Specializations of a superclass
Association
• If two classes in a model need to communicate with each other, there
must be link between them, and that can be represented by an
association (connector). Association can be represented by a line
between these classes with an arrow indicating the navigation
direction
• Object one class are linked with the object of other class
Association
• A class can associate with more then one class
• A person can ride in the car and person can also ride in the bus
Multiplicity
• Important aspect of association
• It tells object of one class that are related to the object of the other
class
• Example like student ,instructor relationship
Aggregation
• Specialized type of association relationship
• A special form of association that specifies a whole-part relationship
between the aggregate (whole) and a component part.
• Aggregation is a special case of association. A directional association
between objects. When an object ‘has-a’ another object, then you
have got an aggregation between them. Direction between them
specified which object contains the other object. Aggregation is also
called a “Has-a” relationship
Aggregation
Composition
• A composition relationship represents a whole–part relationship and
is a type of aggregation. A composition relationship specifies that the
lifetime of the part classifier is dependent on the lifetime of the whole
classifier
•  In a more specific manner, a restricted aggregation is called
composition. When an object contains the other object, if the
contained object cannot exist without the existence of container
object, then it is called composition.
Composition
Composition
How to find classes
Class diagram (Banking system)

You might also like