OOP-Week3 - Class 2UML-CLass Diagram-Pages
OOP-Week3 - Class 2UML-CLass Diagram-Pages
UML Diagrams
• Unified Modeling Language (UML) is a general-purpose modeling
language.
• The main aim of UML is to define a standard way to visualize the way
a system has been designed.
• It is quite similar to blueprints used in other fields of engineering.
• UML is not a programming language, it is rather a visual language.
Why We need UML?
• We need UML (Unified Modeling Language) to visually represent and
communicate complex system designs, facilitating better
understanding and collaboration among stakeholders.
• Complex applications need collaboration and planning from multiple teams
and hence require a clear and concise way to communicate amongst them.
• Businessmen do not understand code. So UML becomes essential to
communicate with non-programmers about essential requirements,
functionalities, and processes of the system.
• A lot of time is saved down the line when teams can visualize processes, user
interactions, and the static structure of the system.
Types of UML Diagram
• Structural Diagram
• Behavioral Diagram
Class Diagram
• A UML class diagram is a visual tool that represents the structure of a
system by showing its classes, attributes, methods, and the
relationships between them.
• Class diagrams are a type of UML (Unified Modeling Language)
diagram used in software engineering to visually represent the
structure and relationships of classes within a system i.e. used to
construct and visualize object-oriented systems.
• In these diagrams, classes are depicted as boxes, each containing
three compartments for the class name, attributes, and methods.
Lines connecting classes illustrate associations, showing relationships
such as one-to-one or one-to-many.
Class Diagram
• Class diagrams provide a high-level overview of a system’s design,
helping to communicate and document the structure of the software.
• They are a fundamental tool in object-oriented design and play a
crucial role in the software development lifecycle.
Class Diagram
UML Class Notation
UML Class Notation
• Class Name:
• The name of the class is typically written in the top compartment of the class
box and is centered and bold.
• Attributes:
• Attributes, also known as properties or fields, represent the data members of
the class. They are listed in the second compartment of the class box and
often include the visibility (e.g., public, private) and the data type of each
attribute.
• Methods:
• Methods, also known as functions or operations, represent the behavior or
functionality of the class. They are listed in the third compartment of the class
box and include the visibility (e.g., public, private), return type, and
parameters of each method.
UML Class Notation
• Visibility Notation:
• Visibility notations indicate the access level of attributes
and methods. Common visibility notations include:
• + for public (visible to all classes)
• - for private (visible only within the class)
• # for protected (visible to subclasses)
• ~ for package or default visibility (visible to classes in
the same package)
Parameter Directionality
• In class diagrams, parameter directionality refers to the indication of
the flow of information between classes through method parameters.
• It helps to specify whether a parameter is an input, an output, or
both. This information is crucial for understanding how data is passed
between objects during method calls.
Parameter Directionality
Parameter Directionality
• In (Input):
• An input parameter is a parameter passed from the calling object (client) to the
called object (server) during a method invocation.
• It is represented by an arrow pointing towards the receiving class (the class that
owns the method).
• Out (Output):
• An output parameter is a parameter passed from the called object (server) back to
the calling object (client) after the method execution.
• It is represented by an arrow pointing away from the receiving class.
• InOut (Input and Output):
• An InOut parameter serves as both input and output. It carries information from the
calling object to the called object and vice versa.
• It is represented by an arrow pointing towards and away from the receiving class.
Relationships between classes
• In class diagrams, relationships between classes describe how classes
are connected or interact with each other within a system.
• There are several types of relationships in object-oriented modeling,
each serving a specific purpose.
Association
• An association represents a bi-directional relationship between two
classes. It indicates that instances of one class are connected to
instances of another class. Associations are typically depicted as a
solid line connecting the classes, with optional arrows indicating the
direction of the relationship.
Association
Aggregation
• Aggregation is a specialized form of association that represents a
“whole-part” relationship. It denotes a stronger relationship where
one class (the whole) contains or is composed of another class (the
part).
• Aggregation is represented by a diamond shape on the side of the
whole class.
• In this kind of relationship, the child class can exist independently of
its parent class.
Aggregation
Composition
• Composition is a stronger form of aggregation, indicating a more
significant ownership or dependency relationship.
• In composition, the part class cannot exist independently of the
whole class.
• Composition is represented by a filled diamond shape on the side of
the whole class.
Composition