Basic Class Diagrams

1. Class Diagram

UML diagram

Visibility Markers: Visibility markers indicate the accessibility of attributes and methods within a class.

  • + (Public): The attribute or method is accessible from any class.
  • - (Private): The attribute or method is only accessible within the same class.
  • # (Protected): The attribute or method is accessible within the same class and its subclasses.
  • ~ (Package): The attribute or method is accessible within the same package.

2. Attributes

visibility name: type [multiplicity] = defaultValue

Uml Attributes Picture

3. Methods

visibility name(parameterList): returnType

Methods

4. Interfaces

Intefaces

5. Abstract Class

Abstract Class

6. Enums

enums

2. Relationships

1. Association ()

“uses-a” relationship between two classes where one class uses or interacts with the other.

Associations

Student class is associated with a Course class, as a student can enroll in multiple courses

2. Aggregation ()

Aggregation represents a "has-a" relationship where one class (the whole) contains another class (the part), but the contained .

Aggregation

Car class has an Engine class but the Engine class can exist without the Car class.

3. Composition( )

Composition represents a strong “has-a” relationship where the part cannot exist without the whole. If the whole is destroyed, the parts are also destroyed.

Composition

House class is composed of Room class but the Room class can not exist without the House class.

4. Inheritance ()

Inheritance (or Generalization) represents an relationship where one class (subclass) inherits the attributes and methods of another class (superclass).

Inheritance

5. Realization ( )

Realization or implementation represents a relationship between a class and an interface, where the class implements the methods declared in the interface. Realization

6. Dependency ()

Dependency represents a uses” relationship where a change in one class (the supplier) may affect the other class (the client). Dependency

Customer class uses an Order class to place order.