Unified Modeling Language (UML)
System modelling and design are critical phases in the software development lifecycle, where we define the architecture, components, and interactions within a system. Unified Modelling Language (UML) is a standard way to visualize the design of a system. In this article, we'll explore system modelling and design using UML and provide Java code examples to illustrate the concepts.
- What is UML?
UML is a standardized modelling language consisting of an integrated set of diagrams to help developers visualize, specify, construct, and document software systems. UML covers both static and dynamic aspects of a system:
Static Modelling: Defines the structure of the system using diagrams like Class Diagram and Entity Relationship Diagram (ERD).
Dynamic Modelling: Defines the behavior and interactions of the system using diagrams like Use Case Diagram, Sequence Diagram, and Activity Diagram.
- Static System Modelling
2.1 Entity Relationship Diagram (ERD)
An ERD helps in identifying and modelling entities, attributes, and relationships within the system.
2.2 Class Diagram
A class diagram shows the system's classes, their attributes, methods, and the relationships among them.
Below are Java code examples for the Student, Person, Employee, and Dashboard classes as described in the class diagram:
student.java
public class Student extends Person {
private int studentID;
private String major;
public Student(String name, int age, int studentID, String major) {
super(name, age);
this.studentID = studentID;
this.major = major;
}
public int getStudentID() {
return studentID;
}
public void setStudentID(int studentID) {
this.studentID = studentID;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
@Override
public String toString() {
return "Student{" +
"studentID=" + studentID +
", major='" + major + '\'' +
'}';
}
}
person.java
public class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
employee.java
public class Employee extends Person {
private int employeeID;
private String department;
public Employee(String name, int age, int employeeID, String department) {
super(name, age);
this.employeeID = employeeID;
this.department = department;
}
public int getEmployeeID() {
return employeeID;
}
public void setEmployeeID(int employeeID) {
this.employeeID = employeeID;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public String toString() {
return "Employee{" +
"employeeID=" + employeeID +
", department='" + department + '\'' +
'}';
}
}
dashboard.java
import java.util.ArrayList;
public class Dashboard {
private ArrayList<Student> students;
private ArrayList<Employee> employees;
public Dashboard() {
this.students = new ArrayList<>();
this.employees = new ArrayList<>();
}
public void addStudent(Student student) {
students.add(student);
}
public void addEmployee(Employee employee) {
employees.add(employee);
}
public ArrayList<Student> getStudents() {
return students;
}
public ArrayList<Employee> getEmployees() {
return employees;
}
@Override
public String toString() {
return "Dashboard{" +
"students=" + students +
", employees=" + employees +
'}';
}
}
- Dynamic System Modelling
3.1 Use Case Diagram
A use case diagram captures the functional requirements of the system by showing interactions between users (actors) and the system.
3.2 Sequence Diagram
A sequence diagram shows how objects interact with each other in a particular sequence of time.
3.3 Activity Diagram
The activity diagram models the workflow and the sequence of activities within the system. It shows the flow of control from one activity to another, highlighting the conditions and decisions involved.
System modelling and design using UML provides a clear and structured way to visualize the architecture and interactions within a system. By combining static and dynamic models, we can comprehensively understand the system's components, relationships, and behaviors. The Java code examples provided here align with the UML diagrams, offering a practical implementation perspective.
Happy coding🚀
Top comments (0)