Lesson 1
Sequence Diagrams used for Modeling
Sequence diagrams in the Unified Modeling Language (UML) are used to model the interactions between objects in a system in a time-sequential manner. They are particularly useful for understanding how objects collaborate to perform a specific task or achieve a particular goal.
Here’s how sequence diagrams are used in system modeling:
-
Visualizing Object Interactions
- Purpose: Sequence diagrams illustrate how objects interact in terms of sending and receiving messages.
-
Representation:
- Objects are represented as lifelines, depicted by vertical dashed lines.
- Interactions are represented as arrows between lifelines.
-
Highlighting Temporal Sequence
- Purpose: They show the chronological order in which messages are exchanged.
- Representation: Time flows from top to bottom in the diagram, with earlier interactions appearing higher than later ones.
-
Defining System Behavior
- Purpose: Sequence diagrams are used to model the dynamic behavior of a system, focusing on how various parts of the system cooperate to execute a process.
- Use Case: Defining interactions in use cases, such as user authentication, data retrieval, or order processing.
-
Modeling Use Cases
- Purpose: Sequence diagrams help refine use cases by showing detailed interactions.
- Example: In an e-commerce system, a sequence diagram might depict the steps for a customer to log in, search for products, and place an order.
-
Analyzing Responsibilities
- Purpose: They help identify which class or object is responsible for specific tasks or actions.
- Outcome: This can influence the assignment of methods to classes in object-oriented design.
-
Identifying Design Flaws
- Purpose: Sequence diagrams can expose inefficiencies or complexities in the interaction flow.
- Example: Excessive back-and-forth messaging between objects might indicate a need for refactoring.
Key Components of a Sequence Diagram
-
Actors: Represent external entities interacting with the system (e.g., users or external systems).
-
Objects/Lifelines: Represent individual objects or roles participating in the interaction.
-
Messages:
- Synchronous: Represent calls that wait for a response.
- Asynchronous: Represent calls that do not require a response.
-
Activation Bars: Indicate the time during which an object is actively processing a message.
-
Loops/Conditions: Represent repeating or conditional interactions.
-
Fragments: Highlight alternative flows, exceptions, or parallel executions.
When to Use Sequence Diagrams
- During requirements analysis to understand and communicate system behavior.
- In design phases to plan and visualize the interaction of objects.
- As a tool for communication among team members to clarify system interactions.
By using sequence diagrams effectively, you can create a clear and shared understanding of how a system operates, ensuring that both developers and stakeholders are aligned on its dynamic behavior.
What is Encapsulation?
The purpose of problem analysis is to define the resointerurces that support the problem domain. The scope of problem analysis includes the purpose and the interfaces of the classes that represent these resources. So far, you have the classes and their purpose. But what method do you use to justify the interfaces for these resources? Interaction diagrams provide a tool for translating use cases into a sequence of communication between specific objects. This communication then translates directly into the object interfaces. The result is an explicit justification for the interfaces you define for each problem domain class.
Encapsulation
As a result of decomposition, software is divided into parts, the meaning of which depends on the paradigm and decomposition. The parts may be modules, abstract data types, packages, or other concepts recognized by the paradigm or the language. The principle of abstraction requires that each part has its interface and its implementation clearly separated from each other. Encapsulation is the principle of exposing only the interface and hiding the implementation of a part of software. In other words, the environment of a part cannot access the implementation, but only its interface.
The interface of a part is specified as something that the part offers to its environment as a contract, or the obligation that the part promises to fulfill at any time.
The implementation, however, is something that is private to the part, and that is assumed to be modifiable without affecting external parts.
If another external part of the software relies only on the interface of the part, the external part remains stable if the implementation of the latter part changes, because the contract specified by the interface must still be satisfied. Let us imagine that a programmer changes the implementation of the part, assuming that other external parts do not rely on the assumptions posed in that implementation.
If an external part violates the encapsulation by relying on the assumptions made in the implementation, that external part will fail after the modification in the former part. This is one of the most frequent causes of errors in traditional software approaches that do not enforce encapsulation.
Encapsulation can be achieved through discipline, by obeying coding rules posed by programmers themselves. However, this approach is highly error-prone. It is crucial, therefore, that the language formally define the rules of encapsulation, and that the modeling tool or compiler check possible violations, in order to avoid errors. In short, encapsulation is yet another concrete technique that supports the general principle of loose coupling of software parts.
It ensures that software parts cannot arbitrarily make interconnections other than as allowed by their contracts. Consequently, it is again a general software engineering principle, not strictly associated with object orientation.
However, as with abstraction, the object paradigm has recognized it as one of its fundamental concepts supported by almost all OO programming and modeling
languages and methods. It can be supported at very different levels and by different formalisms.
Goal of Problem Analysis
The goal of problem analysis is to define the purpose and interface of every problem domain resource.
So far, you have determined the purpose by defining each class and the relationships between the classes in the class diagram. Now you need to add the interfaces. The primary tool for discovering and understanding interfaces is interaction diagrams.
Interaction diagrams (such as sequence diagrams or collaboration diagrams) are a primary tool for discovering and understanding interfaces in a system. These diagrams illustrate how objects or components in a system interact with each other to accomplish tasks, focusing on the messages exchanged between them.
By analyzing these interactions, developers can identify the methods, data, and interfaces needed for effective communication between system components.
- Interaction Diagrams:
The sequence and collaboration diagrams are used to model the interactions between objects. The sequence diagram illustrates the interaction between objects over time. The collaboration diagram illustrates the object interactions across the links between the objects.
- Sequence Diagram:
In this module, the sequence diagram will be used as the primary tool to describe interactions, and these interactions help to define an object's purpose. That is, the ways that an object participates in tasks, how it talks and works with other objects, why the object is needed.
Interfaces are questions and requests that an object is able to respond to. If the problem statement says that an object must be able to answer a question or respond to a request, then the object must have a corresponding interface. There are two types of interaction diagrams: 1) sequence diagrams and 2) communication diagrams.
- Operations and Attributes:
An interface appears as an operation in a class definition. Operations describe what the object can do and what can be done to the object.
Operations can receive, manipulate, and return information. This information appears in the class definition as attributes.
In this module, you will learn:
- The purpose and function of the interaction diagrams
- Sequence diagram notation (review only)
- The value of interactions for object modeling
- How to map use case scenarios to sequence diagrams
- How to discover and document operations from interactions
- How to discover and document attributes from operations