UML and Basic Structure
UML and Basic Structure
•UML is not a programming language but tools can be used to generate code in
various languages using UML diagrams. UML has a direct relation with object
oriented analysis and design.
Features of UML:
1. Visual Representation:
UML uses various diagrams to represent different aspects of a system. These diagrams are
graphical representations of different elements within the system and their relationships.
2. Abstraction:
UML allows developers to create abstract models of a system, which means focusing on
the essential aspects of the system while ignoring the non-essential details. This
abstraction helps in understanding the system at a higher level without getting non-
essential details.
3. Modularity:
UML supports the modular representation of systems. Complex systems can be broken
down into smaller, manageable modules, and these modules can be represented and
understood individually, simplifying the overall system design process.
4. Standardization:
UML provides a standardized way of representing software designs. This standardization
ensures that developers, analysts, and stakeholders, regardless of their background,
can understand the system's structure and behavior using the same set of symbols and
diagrams.
5. Communication:
One of the primary purposes of UML is to facilitate communication between different
stakeholders involved in a software project. It acts as a common language that
developers, designers, clients, and other stakeholders can use to discuss and
understand the system's requirements and design.
UML Diagrams
UML supports various types of diagrams, each serving a specific purpose in the
software development lifecycle:
1. Class Diagrams:
Represent the static structure of the system, showing classes, their attributes,
methods, and relationships.
2. Use Case Diagrams:
Describe the interactions between the system and its users, depicting various use
cases and the actors (users) involved in the system.
3. Sequence Diagrams:
Illustrate how objects interact with each other and the order of these interactions,
displaying the messages exchanged between objects over time.
4. Activity Diagrams:
Depict the workflow in a system, representing the flow of activities and
actions within a process or a use case.
5. State Machine Diagrams:
Model the states of an object and the transitions between these states in
response to events.
6. Component Diagrams:
Show the physical components of the system and their relationships,
helping in understanding the system's architecture.
7. Deployment Diagrams:
Illustrate the physical deployment of software components in hardware
nodes, servers, and other computing devices.
Benefits of UML
• There are a number of goals for developing UML but the most important is to define
some general purpose modeling language, which all modelers can use and it also
needs to be made simple to understand and use.
• UML diagrams are not only made for developers but also for business users, common
people, and anybody interested to understand the system. The system can be a
software or non-software system. Thus it must be clear that UML is not a
development method rather it accompanies with processes to make it a successful
system.
Things
Things are the most important building blocks of UML.
Things can be −
•Structural
•Behavioral
•Grouping
•Annotational
Structural Things
Structural thing can be defined as the static part of the model. They represent the physical and
conceptual elements. Following are the brief descriptions of the structural things.
Interface − Interface defines a set of operations, which specify the responsibility of a class.
Use case −Use case represents a set of actions performed by a system for a specific goal.
Node − A node can be defined as a physical element that exists at run time.
Behavioral Things
State − State is useful when the state of an object in its life cycle is important. It defines
the sequence of states an object goes through in response to events. Events are
external factors responsible for state change
Grouping Things
Note - It is the only one Annotational thing available. A note is used to render comments,
constraints, etc. of an UML element.
Relationship
Relationship is another most important building block of UML. It shows how the elements are
associated with each other and this association describes the functionality of an application.
Dependency
Dependency is a relationship between two things in which change in one element also affects the other.
Association
Association is basically a set of links that connects the elements of a UML model. It also describes how many
objects are taking part in that relationship.
Generalization
Generalization can be defined as a relationship which connects a specialized element with a
generalized element. It basically describes the inheritance relationship in the world of objects.
UML Diagrams
UML diagrams are the ultimate output of the entire discussion. All the elements,
relationships are used to make a complete UML diagram and the diagram represents
a system.
The visual effect of the UML diagram is the most important part of the entire
process. All the other elements are used to make it complete.
Use Case represents the functionality of the system. Hence, other perspectives are connected
with use case.
Design of a system consists of classes, interfaces, and collaboration. UML provides class
diagram, object diagram to support this.
Process defines the flow of the system. Hence, the same elements as used in Design are also
used to support this perspective.
Deployment represents the physical nodes of the system that forms the hardware. UML
deployment diagram is used to support this perspective.
Modeling Techniques in UML
Unified Modeling Language (UML) provides several modeling techniques that allow
software developers to visually represent different aspects of a software system. Here
are some common modeling techniques used in UML:
2. Class Diagrams:
Class diagrams illustrate the structure of the system by showing classes, their attributes,
methods, and relationships between classes. Its elements are Classes, Attributes,
Methods, Associations, Generalization (Inheritance), Aggregation, Composition.
3. Sequence Diagrams:
Sequence diagrams visualize the interactions between objects or components over time.
They show the order of messages exchanged between objects. Its elements are Lifelines
(represent objects), Messages, Activation Bars, Combined Fragments, Interaction Use.
4. Activity Diagrams:
Activity diagrams illustrate the workflow within a system. They show the flow of activities,
actions, and decisions. Its elements are Initial Node, Activity, Decision Node, Merge Node,
Fork Node, Join Node, Swimlanes (represent organizational units).
7. Deployment Diagrams:
Deployment diagrams show the physical deployment of software components on hardware
nodes. They illustrate how software is mapped onto hardware. Its elements are Nodes
(represent hardware devices), Components, Associations.
8. Object Diagrams:
Object diagrams represent specific instances of classes at a particular moment in time. They
show the objects and their relationships during runtime. Its elements are Objects, Links,
Attributes, Associations.
9. Package Diagrams:
Package diagrams organize the elements of a system into packages, allowing for better
management of large systems. Its elements are Packages, Classes, Interfaces,
Dependencies.
These UML modeling techniques are widely used in software engineering to visualize,
specify, construct, and document software systems. The choice of technique depends on
the aspect of the system being modeled and the level of detail required for
communication among stakeholders.
CLASS DIAGRAMS
5. Interface:
Represents a collection of abstract methods. Classes can implement interfaces, ensuring
they provide specific behaviors.
Example: `Drawable` interface might have methods like `draw()` and `resize()`.
6. Abstract Class:
Represents a class that cannot be instantiated on its own. It may contain abstract methods
(methods without implementations) that subclasses must implement. Abstract classes are
denoted by italicized class names.
7. Dependency:
Represents a relationship where one class relies on another class. It is a weaker
relationship compared to association.
Example: Class A depends on class B if class A uses class B as a parameter in one of its
methods.
Class diagrams provide a clear and concise way to represent the static structure of a
system, enabling developers to understand the relationships between different classes
and how they collaborate to achieve specific functionalities within the software
application.
Aggregation and composition in Class Diagram
Aggregation represents a weaker form of association where one class (the whole or
container) contains objects of another class (the part) as part of its state. The part class
objects can exist independently of the whole class. Aggregation is often represented by a
diamond shape on the class diagram. Aggregated objects have an independent lifecycle.
They can exist even if the whole object is destroyed. Aggregation is represented by a
diamond-shaped line connecting the classes, with a line connecting the diamond to the
part class.
Example:
Consider a `University` class and a `Department` class. A department is part of a university,
and it can exist independently even if the university is shut down. This is an example of
aggregation.
Composition (Part-Of Relationship):
Composition represents a stronger form of association where one class (the whole or
container) contains objects of another class (the part) as part of its state. The part class
objects cannot exist without the whole class. If the whole class is destroyed, all its
composed parts are also destroyed. Composition is represented by a filled diamond shape
on the class diagram. Composed objects have a dependent lifecycle. They cannot exist
independently of the whole object. Composition is represented by a filled diamond-
shaped line connecting the classes, with a line connecting the diamond to the part class.
Example:
Consider a `Car` class and an `Engine` class. An engine is a part of a car, and it cannot exist
without a car. If the car is dismantled, the engine is also no longer usable. This is an
example of composition.
So, aggregation and composition both represent relationships between
classes, but they differ in the strength of the relationship and the
lifecycle dependency between the whole and the part objects.
Aggregation implies a weaker, independent relationship, while
composition implies a stronger, dependent relationship. The choice
between aggregation and composition depends on the specific
requirements and semantics of the relationship being modeled in the
software system.
OBJECT DIAGRAM
2. Classes: While class diagrams represent the structure and blueprint of classes, object
diagrams show instances of these classes. Each object belongs to a specific class.
3. Attributes: Objects have attribute values, which are specific to the instances
represented in the object diagram. Attributes reflect the current state of the objects.
In this object diagram, `person1` is an instance of the `Person` class with specific attribute values ("Alice",
30), and it is associated with `address1`, an instance of the `Address` class with specific attribute values
("123 Main St", "Exampleville").
Use of Object Diagrams:
1. Testing Scenarios: Object diagrams can be used to represent specific test cases or
scenarios to ensure that the system behaves as expected in certain conditions.
2. Visualization: They provide a clear visualization of how objects interact with each other
and can help in understanding the runtime behavior of the system.
3. Communication: Object diagrams can be used for communication between stakeholders,
especially when discussing specific instances and relationships within the system.
4. Debugging: During the debugging process, object diagrams can aid in understanding the
state of specific objects and their relationships, helping developers identify issues more
effectively.
Object diagrams, along with class diagrams, sequence diagrams, and other UML diagrams,
provide a comprehensive view of an object-oriented system from different perspectives,
aiding in the understanding, design, and development of software systems.
USE CASES IN UML
Use case diagrams in UML (Unified Modeling Language) serve several crucial purposes in the
software development process, making them an essential tool for communication, analysis,
and design. Here are the key reasons for the need of use case diagrams:
1. Understanding User Requirements: Use case diagrams help in eliciting, organizing, and
understanding user requirements by capturing the interactions between users (actors) and
the system. They provide a clear and concise overview of what the system is supposed to do
from an external perspective.
2. Communication with Stakeholders: Use case diagrams provide a visual and intuitive way
to communicate complex system behavior to stakeholders, including clients, users, and
developers, who may have varying technical backgrounds. They facilitate discussions and
ensure a common understanding among different parties involved in the project.
3. Focus on User Goals: Use cases focus on the goals that users want to achieve with
the system. By identifying and modeling these goals, developers can prioritize features
and functionalities that directly contribute to fulfilling user needs.
4. Basis for System Design: Use case diagrams serve as a foundation for system design
and development. They provide a high-level view of system functionality, guiding the
design process and helping developers understand the system's overall structure and
behavior.
5. Identification of System Boundaries: Use case diagrams help define the boundaries
of the system by identifying external entities (actors) and their interactions with the
system. This clarifies what is inside the system and what is external to it.
6. Use in Requirements Analysis: Use case diagrams are instrumental in requirements
analysis. They aid in identifying, organizing, and prioritizing use cases, which are then
detailed further to capture detailed requirements, including system behaviors, data
flows, and user interactions.
7. Basis for Test Cases: Use cases serve as the basis for generating test cases. Each use case
can be transformed into a series of test scenarios, allowing for systematic testing of the
system's functionalities.
8. Support for Iterative Development: In agile and iterative development methodologies,
use case diagrams provide a flexible framework for understanding user requirements and
adapting the system incrementally based on user feedback and changing needs.
9. Documentation: Use case diagrams, along with detailed use case descriptions, provide
essential documentation for the system. They serve as a reference for developers, testers,
and other stakeholders throughout the development lifecycle.
So, use case diagrams play a central role in capturing user requirements, facilitating
communication, guiding system design, and ensuring that the developed system aligns with
user needs. They provide a user-centered perspective, helping teams focus on building
features that matter most to the end-users of the software.
INTERACTION DIAGRAM IN UML
Sequence diagrams are useful for detailing the interactions between objects in a specific use
case, showing the order of method calls and the flow of data. They provide a clear visual
representation of the flow of control and data between objects, helping in understanding
complex system behavior.
Communication Diagrams (Collaboration Diagrams):
Communication diagrams, also known as collaboration diagrams, emphasize the relationships between objects
and their interactions, focusing on the structural organization of objects in the system. They are less concerned
with the sequence of messages and more concerned with the associations and links between objects.
Communication diagrams are useful for showing the relationships and associations between objects in a system,
providing a clear overview of how objects collaborate. Understanding Object Structure: They help in visualizing
the structural aspects of the system by showing how objects are connected and communicate with each other.
Use of Interaction Diagrams:
1. Use interaction diagrams when modeling complex scenarios where the
interaction between objects needs to be detailed and understood.
2. Use them to illustrate the behavior of objects during specific use cases or
scenarios, emphasizing the flow of messages and data.
So, interaction diagrams in UML are valuable tools for modeling dynamic
aspects of a system, illustrating how objects collaborate, communicate, and
interact over time. The choice between sequence diagrams and
communication diagrams depends on the specific focus of the modeling task:
sequence diagrams emphasize the sequence of messages, while
communication diagrams focus on structural relationships between objects.
Difference between Interaction Diagram and Use Case Diagram
Interaction Diagrams and Use Case Diagrams serve different purposes in the Unified Modeling Language (UML) and are
used to model different aspects of a software system.
Differences are:
Interaction Diagrams:
1. Purpose: Interaction diagrams (such as sequence diagrams and communication diagrams) focus on illustrating the
dynamic behavior of a system by showing how objects interact and communicate with each other over time. They depict
the flow of messages and the sequence of interactions between objects during specific scenarios or use cases.
2. Components:
- Objects: Instances of classes participating in the interaction.
- Messages: Represent the communication and interactions between objects.
- Lifelines: Show the lifespan of objects during the interaction.
- Activation Bars: Indicate the duration of an object's activity.
3. Usage:
1. Interaction diagrams are used to model specific scenarios, showing how objects collaborate to achieve specific
functionalities or tasks.
2. They are particularly useful for detailing the sequence of method calls, the flow of control, and data between objects
during a specific use case.
Use Case Diagrams:
1. Purpose: Use Case Diagrams focus on capturing the functional requirements of a system from an external
perspective. They provide a high-level view of the system's functionalities and how external actors (users, systems)
interact with the system. Use case diagrams do not delve into the internal interactions between objects.
2. Components:
1. Use Cases: Represent specific functionalities or tasks that the system provides to its users.
2. Actors: External entities (users, systems) that interact with the system.
3. Associations: Connect actors with use cases to indicate the relationships between them.
3. Usage:
4. Use case diagrams are used during the early stages of software development to capture, define, and organize
system requirements.
5. They provide a high-level overview of the system's features and the actors involved in using or interacting with
those features.
6. Use case diagrams are valuable for communicating with stakeholders, ensuring that developers and users have a
shared understanding of the system's functionality.
So, main differences between both type of diagrams are:
1. Focus: Interaction diagrams focus on the dynamic behavior and interactions between objects, while use
case diagrams focus on the external functionalities and interactions between actors and the system.
2. Granularity: Interaction diagrams are more detailed and specific, showing the sequence of object
interactions during specific use cases. Use case diagrams provide a high-level, abstract view of the system's
functionalities.
3. Representation: Interaction diagrams use objects, messages, and lifelines to represent interactions
between classes and objects. Use case diagrams use actors and use cases to represent external entities
and system functionalities.
So, interaction diagrams are used to model dynamic behavior and object interactions during specific use
cases, while use case diagrams provide an overview of the system's functionalities and external interactions.
Both types of diagrams are essential tools in software modeling, addressing different aspects of system
development.