Created: 2023-08-28 10:04
Status: #concept
Subject: Programming
Tags: Java Java Class UML

Class Diagram

It is a programmatically generated visual notation to represent Java Class structures.

  • it describes class attributes, constructors, and method contracts, and the connections between other classes, but not the underlying implementation.

Syntax

UML Class Diagram Cheatsheet.png

Describing Inheritance

If a subclass extends a superclass, we represent that relationship with a hollow triangle arrowhead child -|> parent.

  • if we inherit a Java Abstract Class, we add the <<abstract>> italic label on top of the class name and make all its abstract methods italic.
  • similarly, when implementing Java Interfaces, we use the same notation but with <<interface>> on top of the class name and a dashed arrow - -|>.

UML Class Diagram Inheritance.png

Function Signature Syntax

Some examples of common functions in a Person class:

  • +Person(name: String) - the Java Class constructor.
  • -name: String a private attribute.
  • +sayHi(): void - a public Method that takes in noting & returns nothing.
  • +getName(): String - a getter method that returns the this.name instance variable.
  • +setName(String) - a setter method to change this.name of the instance.

References