? Class Diagram Tutorial
? Class Diagram Tutorial
• Classes
• Attributes (data members)
• Methods (functions or operations)
• Relationships between classes
• + Public
• - Private
• # Protected
Relationships:
Order
---------
- orderId: int
- date: Date
+ addProduct()
Product
---------
- productId: int
- name: String
+ getPrice()
Relationships:
Class Diagram
• .
Classes in the Diagram
1. Customer
• Attributes:
o name: String
o email: String
• This class represents the users who place orders on the system.
2. Order
• Attributes:
o orderId: int
o date: Date
• Represents a customer's purchase order.
• An order is made by a customer and may include multiple products.
3. Product
• Attributes:
o productID: int
o name: String
• Represents a product that can be included in one or more orders.
Relationships
Association & Multiplicity
• Customer → Order
There is a line connecting Customer to Order with a diamond and a *:
o This shows a one-to-many relationship.
o One customer can place many orders.
o The diamond indicates aggregation (a customer "has" orders, but orders can exist
independently).
• Order → Product
o There's also a line from Order to Product.
o Suggests that an order contains multiple products.
o This could also be an aggregation (or even composition, if products are
considered part of an order).
Code
Product.java
public class Product {
this.productID = productID;
this.name = name;
return productID;
this.productID = productID;
return name;
this.name = name;
}
Order.java
import java.util.Date;
import java.util.List;
this.orderId = orderId;
this.date = date;
this.products = products;
return orderId;
this.orderId = orderId;
return date;
return products;
this.products = products;
this.products.add(product);
Customer.java
java
CopyEdit
import java.util.List;