Unified Modeling Language (UML)

ICT2622 - Object-Oriented Analysis · Object-Oriented Modelling Techniques

Unified Modeling Language (UML)

Unified Modeling Language (UML) is a standard way to visualize the design of a system. It provides a set of graphic notation techniques to create visual models of object-oriented software systems. UML helps in specifying, visualizing, constructing, and documenting the artifacts of a system.

UML Components

UML consists of several types of diagrams that can be divided into two main categories: structural diagrams and behavioral diagrams.

  • Structural Diagrams: These diagrams represent the static aspects of the system. Examples include class diagrams and component diagrams.
  • Behavioral Diagrams: These diagrams represent the dynamic aspects of the system. Examples include use case diagrams and sequence diagrams.

Importance of UML

UML is important because it provides a common language for developers, designers, and stakeholders. It helps in understanding the system architecture and the relationships between different components. UML also aids in communication among team members, making it easier to share ideas and concepts.

Remember: UML is not a programming language; it is a modeling language used for specification and design.

Basic UML Diagram Types

Here are some of the most commonly used UML diagram types:

Use Case Diagrams

Use case diagrams show the interactions between users (actors) and the system. They help in identifying the functionalities of the system.

Class Diagrams

Class diagrams depict the classes in a system and their relationships. They are essential for understanding the structure of the system.

Sequence Diagrams

Sequence diagrams illustrate how objects interact in a particular scenario of a use case. They show the order of messages exchanged between objects.

Creating UML Diagrams

To create a UML diagram, follow these general steps:

  1. Identify the system: Understand the system requirements and its components.
  2. Select the diagram type: Choose the appropriate UML diagram based on what you want to represent.
  3. Define the elements: Identify the key elements that will be included in the diagram.
  4. Draw the diagram: Use UML notation to create the diagram.
  5. Review and refine: Ensure the diagram accurately represents the system and revise as needed.

UML Notation

UML uses specific symbols and notations. Here are some basic notations:

  • Class: Represented by a rectangle divided into three parts: the class name, attributes, and methods.
  • Association: A line connecting two classes, indicating a relationship.
  • Inheritance: A solid line with a closed arrow pointing to the parent class.
  • Aggregation: A hollow diamond at the parent end of the association line, indicating a whole-part relationship.
  • Composition: A filled diamond at the parent end of the association line, indicating a strong ownership relationship.

Example of a UML Class Diagram

Consider a simple library system. You might have classes like Book, Member, and Loan. Below is how you could represent this in a UML class diagram:

+------------------+        +------------------+        +------------------+  
|      Book        |        |      Member      |        |       Loan       |  
+------------------+        +------------------+        +------------------+  
| - title: String  |        | - name: String   |        | - loanDate: Date |  
| - author: String |        | - memberID: int  |        | - dueDate: Date  |  
+------------------+        +------------------+        +------------------+  
| + getDetails()   |        | + register()     |        | + createLoan()   |  
| + checkAvailability()|     | + getMemberInfo()|        | + returnBook()   |  
+------------------+        +------------------+        +------------------+  

This diagram shows three classes: Book, Member, and Loan. Each class has attributes (like title and author for Book) and methods (like getDetails() for Book).

Watch out: Ensure that you follow the correct UML notation when drawing diagrams. Misusing symbols can lead to misunderstandings.

UML Use Case Diagram Example

Now, let’s create a use case diagram for the library system. The main actors are the Member and the Librarian. The use cases include borrowing and returning books.

+------------------+  
|   Member         |  
+------------------+  
|                  |  
| + borrowBook()   |  
| + returnBook()   |  
+------------------+  
      |  
      |  
+------------------+  
|   Librarian      |  
+------------------+  
|                  |  
| + manageBooks()  |  
+------------------+  

This diagram illustrates how the Member can borrow and return books, while the Librarian manages the books.

UML Sequence Diagram Example

Finally, let’s look at a sequence diagram for the process of borrowing a book:

Member -> Librarian: requestBook()  
Librarian -> Book: checkAvailability()  
Book --> Librarian: availabilityStatus  
Librarian --> Member: confirmBorrow()  

This diagram shows the order of interactions between the Member, Librarian, and Book during the borrowing process.

Tip: Sequence diagrams are useful for visualizing the flow of messages in a particular use case scenario.

Best Practices for UML Diagrams

When creating UML diagrams, consider the following best practices:

  • Keep it simple: Avoid overcrowding diagrams with too many elements.
  • Use standard notation: Stick to UML standards for clarity.
  • Label clearly: Ensure all elements are clearly labelled for easy understanding.
  • Review regularly: Update diagrams as the system evolves.

Summary

  • UML is a standard modeling language for visualizing system designs.
  • It includes structural and behavioral diagrams.
  • Common types of UML diagrams are use case diagrams, class diagrams, and sequence diagrams.
  • UML notation includes specific symbols for classes, associations, and relationships.

Check your understanding

  1. What are the two main categories of UML diagrams?
  2. Explain the difference between aggregation and composition in UML.
  3. What is the purpose of a sequence diagram?
  4. List two best practices for creating UML diagrams.