Class Diagrams

Model object-oriented systems and relationships

Quick Start

Basic Syntax

classDiagram
class Animal {
+String name
+makeSound()
}

Live Preview

Loading preview...

Visibility Modifiers

+
Public
-
Private
#
Protected
~
Package/Internal

Relationship Types

A <|-- B
Inheritance (B extends A)
A <|.. B
Interface implementation
A --o B
Aggregation (has-a)
A --* B
Composition (part-of)
A --> B
Association
A -- B
Link (solid line)
A ..> B
Dependency
A ..|> B
Realization

Complete Examples

Basic Class Diagram
Simple class with attributes and methods

Code

classDiagram
    class Animal {
        +String name
        +int age
        +makeSound()
        +move()
    }
    
    class Dog {
        +String breed
        +bark()
        +wagTail()
    }
    
    Animal <|-- Dog

Preview

Loading preview...

Use Case

Perfect for basic object-oriented modeling and inheritance

E-commerce System
Complex system with multiple relationships

Code

classDiagram
    class User {
        +String email
        +String password
        +String name
        +login()
        +logout()
        +updateProfile()
    }
    
    class Order {
        +String id
        +Date orderDate
        +String status
        +float total
        +addItem()
        +removeItem()
        +calculateTotal()
    }
    
    class Product {
        +String id
        +String name
        +float price
        +int stock
        +String description
        +updateStock()
        +getDetails()
    }
    
    class OrderItem {
        +int quantity
        +float unitPrice
        +getSubtotal()
    }
    
    User ||--o{ Order : places
    Order ||--o{ OrderItem : contains
    Product ||--o{ OrderItem : includes
    
    class PaymentService {
        <<interface>>
        +processPayment()
        +refund()
    }
    
    class CreditCardPayment {
        +String cardNumber
        +String expiryDate
        +processPayment()
        +refund()
    }
    
    PaymentService <|.. CreditCardPayment

Preview

Loading preview...

Use Case

Ideal for modeling complex business systems and relationships