Shopping cart class diagram
A cart composes cart items, and each item refers to a product. Delete the cart and its items go, but products stay.
The diagram
Reading it step by step
- 'Cart' (class): 0 attributes, 2 methods.
- 'CartItem' (class): 1 attributes, 1 methods.
- 'Product' (class): 2 attributes, 0 methods.
- 'Cart' is composed of 'CartItem' (holds).
- 'CartItem' is associated with 'Product'.
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Cart | Class | holds +total() int, +clear() void · → CartItem(holds) |
| CartItem | Class | holds +quantity int, +subtotal() int · → Product · ← Cart |
| Product | Class | holds +title String, +price int · ← CartItem |
Symbols used here
| Symbol | Meaning |
|---|---|
| Class | A box with name, attributes and methods. |
| Composition | Filled diamond at the whole; parts die with it. |
| Association | One class knows and uses another; solid arrow. |
Diagram text
Paste this text into the editor to get the same picture, then change the names to fit your own work.
# Shopping cart class diagram
classDiagram
class Cart {
+total() int
+clear() void
}
class CartItem {
+quantity int
+subtotal() int
}
class Product {
+title String
+price int
}
Cart *-- CartItem : holds
CartItem --> Product