UNIT-III-SDUML
UNIT-III-SDUML
Static Structure Diagrams in UML represent the static view of a system, focusing on its
architecture rather than its dynamic behavior. They depict the building blocks of a system,
such as classes, objects, components, and their relationships, providing a foundation for
system design and implementation.
1. Class Diagram
o Represents the classes in a system along with their attributes, operations,
and relationships (e.g., association, generalization, aggregation).
o Key elements:
▪ Classes: Show the structure of entities.
▪ Attributes and Operations: Represent properties and methods.
▪ Relationships: Show connections, such as inheritance or associations.
o Use Case: Used for designing object-oriented systems.
2. Object Diagram
o A snapshot of objects and their relationships at a specific time.
o Focuses on instances of classes rather than the classes themselves.
o Use Case: Used for understanding system states at runtime.
3. Component Diagram
o Describes the physical structure of code components.
o Focuses on modules, libraries, and interfaces.
o Use Case: Useful for deployment and implementation planning.
4. Deployment Diagram
o Represents the physical architecture of a system.
1
o Focuses on hardware nodes, software components, and their configurations.
o Use Case: Useful for designing distributed systems.
5. Package Diagram
o Shows how classes or components are grouped into packages.
o Highlights dependencies between packages.
o Use Case: Used to organize large systems into manageable units.
1. Classes/Objects:
o Represent entities with attributes and methods.
2. Relationships:
o Association: A connection between two classes.
o Aggregation: A whole-part relationship.
o Composition: A stronger form of aggregation where parts cannot exist
independently.
o Generalization: Inheritance relationships between classes.
o Dependency: Indicates that one element uses another.
3. Multiplicity:
o Defines how many instances of a class can be associated with another.
4. Interfaces:
o Represent a contract that a class must adhere to.
2
Examples
● Objects:
o Customer: John Doe
o Order: #123
o Product: Laptop
● Components:
o UserInterface, Database, PaymentGateway
● Interfaces:
o PaymentAPI
3
The Class Diagram Model
A Class Diagram is a static structure diagram in UML that describes the blueprint of a system
by modeling its classes, attributes, operations, and relationships. It provides a foundation for
object-oriented design and is widely used in software engineering to visualize and design the
structure of software systems.
1. Classes:
o Represent entities in a system.
o Typically depicted as rectangles divided into three compartments:
▪ Top: Class name (e.g., Customer).
▪ Middle: Attributes (e.g., name, email).
▪ Bottom: Operations (e.g., addToCart(), placeOrder()).
2. Attributes:
o Represent the properties of a class.
o Syntax: <visibility> <attributeName>: <type>
o Example: +name: String
3. Operations:
o Represent the methods or behaviors of a class.
o Syntax: <visibility> <methodName>(parameters): <returnType>
o Example: +calculateTotal(): float
4. Visibility Modifiers:
o Public (+): Accessible to all classes.
o Private (-): Accessible only within the class.
o Protected (#): Accessible within the class and its subclasses.
5. Relationships:
o Association: A connection between two classes.
▪ Example: A Customer is associated with an Order.
o Multiplicity: Specifies the number of instances in a relationship.
▪ Example: 1..* indicates "one to many."
o Aggregation: A "whole-part" relationship where parts can exist
independently.
▪ Example: A Library contains Books.
4
o Composition: A stronger aggregation where parts cannot exist independently.
▪ Example: A House has Rooms.
o Generalization: Inheritance between a superclass and subclasses.
▪ Example: Person is a general class; Customer and Employee are
specific classes.
o Dependency: One class uses or depends on another.
▪ Example: Invoice depends on Payment.
6. Interfaces:
o Represent a contract that a class must adhere to.
o Example: PaymentProcessor interface with processPayment() method.
1. Identify Classes:
o Extract nouns from the system requirements or use cases.
o Example: Customer, Order, Product.
2. Define Attributes:
o Assign properties relevant to each class.
o Example: Order has attributes orderID and date.
3. Define Operations:
o Specify behaviors or methods for each class.
o Example: Customer has login() and register().
o
4. Establish Relationships:
o Identify and model associations, dependencies, or hierarchies between classes.
o Example: Customer places an Order.
5. Use Multiplicity:
o Define the number of instances involved in associations.
o Example: A Cart can contain multiple Products (1..*).
An example of UML class diagram which shows a domain model for online shopping. The
purpose of the diagram is to introduce some common terms, "dictionary" for online shopping
- Customer, Web User, Account, Shopping Cart, Product, Order, Payment, etc. and
5
relationships between. It could be used as a common ground between business analysts and
software developers.
Each customer has unique id and is linked to exactly one account. Account owns shopping
cart and orders. Customer could register as a web user to be able to buy items online.
Customer is not required to be a web user because purchases could also be made by phone or
by ordering from catalogues. Web user has login name which also serves as unique id. Web
user could be in several states - new, active, temporary blocked, or banned, and be linked to
a shopping cart. Shopping cart belongs to account.
Account owns customer orders. Customer may have no orders. Customer orders are sorted
and unique. Each order could refer to several payments, possibly none. Every payment has
unique id and is related to exactly one account.
Each order has current order status. Both order and shopping cart have line items linked to a
specific product. Each line item is related to exactly one product. A product could be
associated to many line items or no item at all.
6
Relationships:
A UML Class Diagram is a structural diagram that represents the static structure of a system
by modeling its classes, attributes, operations, and the relationships between them. Here is a
detailed explanation of the notations used in a class diagram.
1. Class Representation:
○ A class is represented as a rectangle divided into three compartments:
1. Top: The name of the class.
2. Middle: Attributes of the class.
3. Bottom: Operations (methods) provided by the class.
Syntax:
ClassName
attributes
operations
7
Example
Attributes:
Example:
- width: Float
- height: Float
Operations:
Example:
+ calculateArea() : Float
+ setDimensions(w: Float, h: Float) : void
Attributes in a class diagram represent the properties or data fields of a class. They define
the characteristics or state that objects of the class can hold. Each attribute is typically
associated with a name, a type, and sometimes a default value or additional constraints.
8
Components of an Attribute
1. Visibility:
2. Name:
1. +name: String[
o Public name attribute of type String.
2. -salary: double = 50000.0
o Private salary attribute of type double with a default value of 50000.0.
3. #marks: List<int> [0..*]
o Protected marks attribute, a list of integers, with zero or more instances.
4. ~level: int {1..5}
o Package-level level attribute with values constrained between 1 and 5.
9
Describing Attributes with Examples
-customerID:
Unique identifier for the customer.
int
The email address of the customer, accessible by the class and its
#email: String
subclasses.
-totalAmount:
Total cost of the order.
float
1. Clarity:
o Use private visibility (-) for most attributes to enforce data encapsulation.
4. Data Types:
Customer
-customerID: int
+name: String
#email: String
+age: int {> 0}
+register(): void
+login(): boolean
Operations descriptions
11
In UML (Unified Modeling Language), operations are behaviors or functions associated with
a class or an interface. They represent actions or services that a class can perform and are
defined within the context of a class diagram.
1. Definition:
○ Operations specify what a class can do or what behavior it provides. They are
analogous to methods in programming languages.
○ Each operation has a signature that includes its name, parameters, and return
type.
2. Notation:
○ Represented in the third compartment of a class box in a class diagram,
below attributes.
○ Syntax:
Example:
Visibility:
Parameters:
Return Type:
● Specifies the type of data returned by the operation. If no value is returned, the return
type is often omitted or noted as void.
Operation Modifiers:
Rectangle
- width: Float
- height: Float
+ setDimensions(width:
Float, height: Float) : void
+ calculateArea() : Float
+ calculatePerimeter() : Float
In the Static Model of UML, connections represent the relationships and links between the
structural elements of a system, such as classes, objects, and components. These connections
are foundational for defining the architecture and data flow within the system. The key types
of connections in the static model include associations, dependencies, generalizations,
realizations, and more.
13
Types of Connections in UML Static Models
Association:
Association relationship is a structural relationship in which different objects are linked within
the system. It exhibits a binary relationship between the objects representing an activity. It depicts
the relationship between objects, such as a teacher, can be associated with multiple teachers.
It is represented by a line between the classes followed by an arrow that navigates the direction,
and when the arrow is on both sides, it is then called a bidirectional association. We can specify
the multiplicity of an association by adding the adornments on the line that will denote the
association.
The composition and aggregation are two subsets of association. In both of the cases, the
object of one class is owned by the object of another class; the only difference is that in
composition, the child does not exist independently of its parent, whereas in aggregation, the
child is not dependent on its parent i.e., standalone. An aggregation is a special form of
association, and composition is the special form of aggregation.
14
● Definition: Represents a structural relationship between two or more classes that
shows how objects of these classes are related to each other.
● Notation: Solid line connecting classes.
● Details:
○ Multiplicity: Specifies the number of instances that can participate in the
relationship.
■ Example: 1, 0..1, *, 1..*.
○ Role Names: Labels at the ends of the line to describe the role of each class in
the association.
○ Direction: Can have arrows to show navigability.
Example:
Aggregation:
15
For example:
Here we are considering a car and a wheel example. A car cannot move without a wheel. But the
wheel can be independently used with the bike, scooter, cycle, or any other vehicle. The wheel
object can exist without the car object, which proves to be an aggregation relationship.
Guidelines:
● Independence: Ensure that the part objects can exist independently of the whole
object.
○ Example: A Department has Employee objects, but employees can exist
without a department.
● Multiplicity: Clearly define the multiplicity at both ends to indicate how many parts
are involved in the relationship.
○ Example: 1 Department aggregates 1..* Employees.
● Role Clarity: Use meaningful role names for better understanding.
○ Example: A Car aggregates Tires with the role wheels.
● Avoid Overuse: Only use aggregation when there is a meaningful "whole-part"
relationship. Overuse can clutter the diagram.
Composition:
Definition: A stronger form of aggregation where the part cannot exist independently of the
whole.
Example:
In the example given below, the composition association relationship connects the Person
class with Brain class, Heart class, and Legs class. If the person is destroyed, the brain, heart,
and legs will also get discarded.
16
Guidelines:
● Lifecycle Dependency: Ensure the part cannot logically exist without the whole.
○ Example: A House and its Rooms—if the house is destroyed, so are its
rooms.
● Encapsulation: Use composition for a stronger level of encapsulation between the
whole and the parts.
● Multiplicity: Clearly specify multiplicities to show how many parts are required.
○ Example: 1 House contains 1..* Rooms.
● Logical Relationship: Use composition only if the parts have no independent
significance without the whole.
● Consistency: Ensure the diagram reflects the logical dependency in the real-world
model.
● Role Naming: Add roles to clarify the relationship and improve understanding.
○ Example: House contains Rooms with the role livingArea.
Generalization:
Generalization relationships are utilized in class, component, deployment, and use case
diagrams to specify that the child inherits actions, characteristics, and relationships from its
parent.
To meet UML's standard, it necessitates usage of the same types of model elements in the
generalization relationship, i.e., generalization relation can either be used between actors or
between use cases, but not between an actor and a use case.
17
The parent model element can have as many children, and also, the child can have one or more
parents. But most commonly, it can be seen that there is one parent model element and multiple
child model elements. The generalization relationship does not consist of names. The
generalization relationship is represented by a solid line with a hollow arrowhead pointing
towards the parent model element from the child model element.
In the generalization stereotype, there are two types of constraints that are complete and
incomplete to check if all the child objects are involved or not in the relationship.
Example:
As we know, the bank account can be of two types; Savings Account and Credit Card
Account. Both the savings and the credit card account inherits the generalized properties from
the Bank Account, which is Account Number, Account Balance, etc.
Dependency:
Dependency in UML is a relationship that represents how one element depends on another
for its specification or implementation. It typically signifies a "uses," "needs," or "relies
upon" relationship between two elements in a system.
Characteristics of Dependency
● Definition:
○ A unidirectional relationship where a change in the independent (supplier)
element may require a change in the dependent (client) element.
○ Indicates that one element relies on the functionality or existence of another
element.
● Notation:
○ Represented as a dashed arrow pointing from the dependent element (client)
to the independent element (supplier).
○ Optional stereotype (e.g., <<uses>>, <<calls>>,
<<instantiates>>, etc.) may be added for clarity.
Example:
● Definition: A relationship where one class depends on another for its specification or
implementation. It signifies a "uses" or "needs" relationship.
● Notation: Dotted arrow pointing from the dependent class to the class it depends on.
Directionality:
● Always points from the dependent element (client) to the independent element
(supplier).
Types of Dependencies
1. Usage Dependency:
○ Represents that one class uses another class, usually in the form of invoking
its methods or accessing its data.
○ Example: A Report class depends on a Database class for data fetching.
2. Instantiation Dependency:
19
○ Indicates that one class creates an instance of another.
○ Example: A Controller class depends on a View class to create a user
interface.
3. Abstraction Dependency:
○ Links an abstraction to its realization.
○ Example: An interface (IShape) has a dependency on its implementation
class (Circle).
4. Permission Dependency:
○ Indicates permission granted for one package or component to use elements of
another.
○ Example: A Client package depends on a Server package for accessing its
services.
1. Traceability:
○ Makes it easier to understand and trace dependencies between elements in
complex systems.
Stereotypes:
Interface Connection:
Multiplicity:
● Specifies how many instances of one class can be associated with a single instance of
another class in an association.
● Examples:
○ 1: Exactly one.
○ 0..1: Zero or one.
○ *: Zero or more.
○ 1..*: One or more.
● Structure Representation: They capture the foundational relationships that define the
structure of the system.
● Behavior Prediction: Help infer how elements interact and how the system behaves.
● Communication: Provide a clear and standardized way to describe relationships,
making it easier for teams to understand system architecture.
21