Diagram Desk

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

Cart+total() int+clear() voidCartItem+quantity int+subtotal() intProduct+title String+price intholds
Class diagram · 9 shapes

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

ShapeSymbolConnections
CartClassholds +total() int, +clear() void · → CartItem(holds)
CartItemClassholds +quantity int, +subtotal() int · → Product · ← Cart
ProductClassholds +title String, +price int · ← CartItem

Symbols used here

SymbolMeaning
ClassA box with name, attributes and methods.
CompositionFilled diamond at the whole; parts die with it.
AssociationOne class knows and uses another; solid arrow.

All class diagram symbols and how to draw

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

More class diagram examples

All SeewolLabs tools