CS F213 Objected Oriented Programming Labsheet 15
Spring 2024
UML Diagrams
Definition
UML, which stands for Unified Modeling Language, is a way to visually represent the architecture, design, and implementation of complex software systems. When you’re writing code, there are thousands of lines in an application, and it’s difficult to keep track of the relationships and hierarchies within a software system. UML diagrams divide that software system into components and subcomponents.
Types of UML Diagrams
Structure Diagrams :
Class Diagram
Component Diagram
Deployment Diagram
Object Diagram
Package Diagram
Profile Diagram
Composite Structure Diagram
Behavioral Diagrams:
Use Case Diagram
Activity Diagram
State Machine Diagram
Sequence Diagram
Communication Diagram
Interaction Overview Diagram
Timing Diagram
Structure Diagrams
These diagrams show the things in the modeled system. In a more technical term, they show different objects in a system. Some of the important structure diagrams are defined below.
Class Diagram
Class diagrams are the main building block of any object-oriented solution. It shows the classes in a system, attributes, and operations of each class and the relationship between each class.
A class is represented by a rectangle that contains three compartments stacked vertically—the top compartment contains the class’s name and is mandatory, but the bottom two compartments give details about the class attributes and class operations or behaviors Different relationships between classes are shown by different types of arrows. Below is an example of a class diagram for a order processing system.
Component Diagram
A component diagram displays the structural relationship of components of a software system. These are mostly used when working with complex systems with many components. Components communicate with each other using interfaces. The interfaces are linked using connectors. The image below shows a component diagram.
Deployment Diagram
A deployment diagram shows the hardware of your system and the software in that hardware. Deployment diagrams are useful when your software solution is deployed across multiple machines with each having a unique configuration. Below is an example deployment diagram.
Object Diagram
Object Diagrams, sometimes referred to as Instance diagrams are very similar to class diagrams. Like class diagrams, they also show the relationship between objects but they use real-world examples.
They show what a system will look like at a given time. Because there is data available in the objects, they are used to explain complex relationships between objects.
Package Diagram
As the name suggests, a package diagram shows the dependencies between different packages in a system.
Behavioral Diagrams
These show what should happen in a system. They describe how the objects interact with each other to create a functioning system. Some of the important behavioral diagrams are defined below.
Use Case Diagram
As the most known diagram type of the behavioral UML types, Use case diagrams give a graphic overview of the actors involved in a system, different functions needed by those actors and how these different functions interact.
It’s a great starting point for any project discussion because you can easily identify the main actors involved and the main processes of the system.
Activity Diagram
Activity diagrams represent workflows in a graphical way. They can be used to describe the business workflow or the operational workflow of any component in a system. Sometimes activity diagrams are used as an alternative to State machine diagrams.
State Diagram
State machine diagrams are similar to activity diagrams, although notations and usage change a bit. They are sometimes known as state diagrams or state chart diagrams as well. These are very useful to describe the behavior of objects that act differently according to the state they are in at the moment. The State machine diagram below shows the basic states and actions.
Sequence Diagram
Sequence diagrams in UML show how objects interact with each other and the order those interactions occur. It’s important to note that they show the interactions for a particular scenario. The processes are represented vertically and interactions are shown as arrows.
How to use UML lab
Go to https://www.uml-lab.com/
Click on Download at the top right corner
Install the setup on your local machine
Open the application
You will be presented with the welcome screen
Take the UML Lab tour to understamd the basic functionalities of the software.
The first module teches you how to prepare and open a project using Navigate option
The second module shows the main step : To open the "New UML Model" wizard, in the "Package Explorer" right-click the "UML Lab Shop Example" project and select "New > UML Model and Class Diagram" -> Finish.
To add more items to diagram: Add the "Employee" class to the right list by double-clicking "Employee" on the left list -> Click 'OK'
Now you will have the diagram of Employee. To reveal the "Person" class in the diagram, click the "parents" button above the "Employee" class.
The third module shows how to edit the UML and get the corresponding code for the same, Left-click on the "Employee" class and type "applyForLeave(numberOfDays)" -> Enter -> Ctrl + S
To add classes in the UML press and hold the left mouse button over an empty area in the diagram, drag it to draw a box, and release the button. Rename it to say, Manager
To add connections in the UML while hovering the "Manager" class, press and hold the right mouse button, drag it to "Person", and release it. Select "Create Generalization" from the context menu showing up.
The next module shows how to sync UML with changes in the source code. Right-click on the class "Manager" in the class diagram and select "Navigate To > Source" in the context menu
Add a new field "private int salesVolume;" to the class "Manager" by typing into the Java editor that just opened.
Generate a get and set method for this field. Right-click into the Java editor and select "Source > Generate Getters and Setters..." from the context menu. Check the field "salesVolume" in the upcoming dialog and confirm the dialog by choosing "OK".
Once you save it go to the UML file again to see the chages. The software autromatically syncs the code and the diagram.
This way the software can be used to make different UML diagrams from your source code if you are a programmer and want to reflect your flow of the program visually. The vice versa can also be done through UML Labs.
Last updated