Given the following code I have to draw the corresponding class diagram:
public class Shop
{
List<Client> clients;
Storage store;
User chief;
Set<Invoice> invoices;
}
public class Invoice
{
Map<Product, Row> rows;
Client client;
}
public class Client{}
public class Product{}
public class Storage
{
Map<Integer, Product> products;
}
public class Row
{
Product p;
double qty;
}
On draw.io I produced the following design:
Focus of my question is on
– Relation between Invoice and row:
Is it correct to draw the qualified association like so? On draw.io I found no option to depict this particular case. I built it by dragging Product class to be adjacent to Invoice.
-
Relation between Storage and Product.
Is it correct? Or should I represent it also like a qualified association using class Integer as qualifier? -
Do you see any error on relation arrows or cardinality?
Best Answer
I think you need to model Product as a distinct class to make it clear that a Storage may have Products that are not yet included in any Invoice.
You could model Row as an association class for the Invoice-Product association:
Otherwise your diagram seems ok. The structure of Storage seems a bit funny though. If it should keep record of the amount of items, then it probably should have a
Map<Product, Integer>
instead ofMap<Integer, Product>
.