Understanding the Difference between Extend and Include in Use Case Diagrams

Extend vs include in use case diagram

In the world of software development, use case diagrams are a visual representation of the interactions between users (known as actors) and a system. They help to define the functionality of a system and provide a clear understanding of how it is expected to be used. Two important concepts in use case diagrams are “extend” and “include”.

“Extend” is used to represent optional functionality that can be added to a use case under certain conditions. It allows for the reuse of existing use cases by providing an extension point where additional behavior can be added. This can improve the modularity and flexibility of a system, as it allows for different combinations of functionalities depending on the specific needs of users.

“Include”, on the other hand, is used to represent the dependency between two use cases. It indicates that one use case includes the behavior of another use case. This means that the included use case is always executed as part of the including use case. Including use cases can be seen as building blocks for the overall functionality of a system.

In summary, extend and include are two key concepts in use case diagrams that help to define the behavior and functionality of a system. While extend represents optional functionality that can be added under certain conditions, include represents the dependency between different use cases. Both extend and include are useful tools for designing modular and flexible systems that can cater to different user needs.

Definition of Extend

The “extend” relationship in a use case diagram is used to model optional behavior that can be added to a base use case. It represents an alternative or exceptional flow that can be triggered under certain conditions. In other words, the “extend” relationship allows for the extension of the base use case by including additional steps or actions. This relationship is denoted by a dashed arrow from the extending use case to the base use case, with the keyword “extends” written near the arrow.

When a use case extends another use case, it means that the extending use case can be inserted into the base use case, but it is not mandatory. It provides flexibility and allows for variations in the system behavior based on certain conditions or additional requirements. The extending use case typically occurs after certain steps or actions in the base use case and may modify or enhance its behavior.

There are several key points to keep in mind when using the “extend” relationship in a use case diagram:

  • The extending use case must be optional and should not affect the normal flow of the base use case.
  • The extending use case must have a condition or trigger that determines when it should be executed.
  • The extending use case may have its own steps, actions, or interactions that modify the behavior of the base use case.
  • The base use case should remain independent and be able to function without the extending use case.
  • The “extend” relationship should be used when the behavior being added is optional or exceptional, and not a fundamental part of the base use case.

In summary, the “extend” relationship in a use case diagram allows for the modeling of optional behavior that can be added to a base use case. It provides flexibility and allows for variations in system behavior based on certain conditions or additional requirements.

Definition of Include

Include is a relationship that is used in use case diagrams in the Unified Modeling Language (UML). This relationship represents the fact that one use case includes the functionality of another use case. It is denoted by a dashed arrow with an open arrowhead pointing from the including use case to the included use case.

The include relationship is used when one use case requires the behavior of another use case to be included in its own behavior. This means that the including use case cannot be fully executed without the functionality provided by the included use case. The included use case is considered to be optional and can be reused in multiple including use cases.

The include relationship is useful in modeling complex systems where there are common behaviors that are shared among multiple use cases. By including these common behaviors in separate use cases, we can avoid redundancy and improve the modularity and reusability of the system. This relationship can also be used to capture variations or alternative flows within a use case, where certain steps are only executed under specific conditions.

In summary, the include relationship in a use case diagram represents the fact that one use case includes the functionality of another use case. It is used to capture common behaviors and improve modularity and reusability in complex systems.

Differences between Extend and Include

The Extend and Include relationships are both used in use case diagrams to show the relationships between different use cases. However, there are some key differences between these two relationships.

Extend:

  • The Extend relationship is used when one use case can be optionally extended by another use case.
  • The extending use case is optional and not always executed.
  • The extending use case adds additional functionality to the extended use case.
  • The extending use case is not required for the extended use case to be completed successfully.
  • The extending use case is activated by a condition or trigger specified in the extended use case.
  • An arrow with an open arrowhead is used to represent the Extend relationship.

Include:

  • The Include relationship is used when one use case includes another use case.
  • The included use case is mandatory and always executed.
  • The included use case represents a set of actions or steps that are included in the main use case.
  • The included use case cannot be completed successfully without the inclusion of the main use case.
  • An arrow with a closed arrowhead is used to represent the Include relationship.

In summary, the Extend relationship is used to show optional and additional functionality that can be added to a use case, while the Include relationship is used to show mandatory steps or actions that are included in a main use case.

Use case diagram example with Extend

Extend is a relationship in use case diagrams that represents the optional behavior of a use case. It allows for the inclusion of additional steps or alternative flows in a use case, which are not always necessary for the main flow of the use case.

For example, let’s consider a use case diagram for an online shopping system:

  • Actor: Customer
  • Use Case: Add Item to Cart
  • Use Case: Checkout
  • Use Case: Apply Discount Code
  • Use Case: Place Order

In this example, the “Apply Discount Code” use case may be optional. It can be extended from the “Checkout” use case, meaning that it can be included in the flow of events if the customer has a discount code to apply, but it is not always necessary for the overall process of checking out.

The “Apply Discount Code” use case can have an extending relationship with the “Checkout” use case, represented by a dashed arrow with the “extend” keyword. This indicates that it extends the behavior of the “Checkout” use case under certain conditions.

By using the extend relationship in the use case diagram, it becomes clear that the “Apply Discount Code” use case is an optional step in the overall process of checking out, allowing for flexibility in the system’s functionality.

Use case diagram example with Include

Use case diagram example with Include

In a use case diagram, the “include” relationship is used to represent the inclusion of one use case by another. This means that the included use case is a part of the behavior of the including use case. It is used to show that the behavior of the included use case is always executed when the including use case is executed. This relationship is denoted by a dotted arrow with an open diamond at the including use case end.

For example, let’s consider an online shopping system. One of the use cases in this system is “Place Order”. This use case includes the use case “Select Products”. This means that the behavior of “Select Products” is always performed when “Place Order” is executed. The “Select Products” use case allows the user to choose the products they want to purchase.

Another use case in the online shopping system is “Checkout”. This use case includes the use case “Select Shipping Address”. This means that the behavior of “Select Shipping Address” is always executed when the “Checkout” use case is executed. The “Select Shipping Address” use case allows the user to choose the address to which the ordered products will be shipped.

The “include” relationship in a use case diagram helps to show the modular structure of the system and how the different use cases are connected. It allows for better understanding of the behavior of the system and how the different use cases interact with each other.

When to use Extend?

When to use Extend?

In a use case diagram, the Extend relationship is used to represent optional behavior that can be added to a base use case. It is used when one use case can be extended by the inclusion of additional behavior under certain conditions.

  • The Extend relationship should be used when the additional behavior is optional and not always performed.
  • It is used to show that the base use case can be extended to include the optional behavior, but it is not mandatory.
  • The Extend relationship is typically used to handle variations or exceptional scenarios in the system.
  • It is used when there are alternative flows or exceptional conditions that are not always present in the main flow of the use case.
  • Use Extend when you want to keep the main use case simple and separate the additional behavior into separate use cases.

Overall, the Extend relationship in a use case diagram is used to show optional and additional behavior that can be included in a base use case, but is not always performed. It is a way to handle variations, exceptional scenarios, or alternative flows in the system. By using Extend, you can keep the main use case focused and separate the optional behavior into separate use cases.

When to use Include?

The include relationship in a use case diagram is used to show that one use case depends on another use case. It represents the flow of control between use cases. This relationship is used when one use case calls or invokes another use case to accomplish a part of its functionality.

There are several situations in which the include relationship should be used:

  • Reusability: When a certain set of steps or functionality is used by multiple use cases, it is better to separate that functionality into its own use case and include it in the relevant use cases. This promotes reusability and simplifies the understanding and maintenance of the use case diagram.
  • Complexity: When a use case becomes too complex, it can be broken down into smaller, more manageable use cases. The main use case will then include the smaller use cases to ensure that all necessary steps are performed.
  • Conditional Steps: When there are specific steps that are optional or conditional based on certain conditions, the include relationship can be used to represent those steps as separate use cases. The main use case can then include these optional use cases depending on the conditions.
  • Step-by-Step Execution: When a use case requires a specific sequence of steps to be executed, the include relationship can be used to represent that sequence. Each step can be represented as a separate use case, which are then included in the main use case in the required sequence.

Overall, the include relationship is used to simplify and organize the flow of control between use cases. It helps in breaking down complex functionality, promoting reusability, and representing conditional or sequential steps in a clear and understandable manner.

Posted in doc