I'm quite confused about how to implement correctly in java code, associations drawn on a UML class diagram.
Imagine we have just two classes (i.e. Order and Product) with association specified in different ways, these associations could be drawn as following cases A,B or C:
Since I've found this answer: https://stackoverflow.com/a/2293760/3248096 that talks about (association with an arrow and navigability direction)
My first question is about difference on implementing B compared to A. On A implementation I would write:
public class Order{
private Set<Product> products;
}
public class Product{
private Set<Order> orders;
}
On B implementation :
public class Order{
private Set<Product> products;
}
public class Product{
//no references properties back to order from here since no back navigability
...
}
Second question is about C model: What's the best way (is there one?) to represent by implementation a limited cardinality from 0 to 4? (Doesn't have much sense that a Product could have 0 to 4 parent orders. It's more about understanding modeling vs. code)
public class Product{
//Array(4) orders...?
}