tags:

views:

69

answers:

3

What does it mean when you have something as the following picture? alt text

Each Customer has none, one or more Orders while each Order has only one Customer?

And in relationship to the following one: alt text

What does the black diamond mean in this context? How is that black diamond called?

Thanks

+4  A: 

In the first picture, an Order can only be associated to one Customer, while one Customer can have many Order's.

The black diamond in the second example is called a composition, or an associated relationship. Composition usually has a strong life cycle dependency between instances of the container class and instances of the contained class or classes. In your case Order is the container class and the Customer is its contained class.

Reference:

Anthony Forloney
http://en.wikipedia.org/wiki/Class_diagram also describes some additional elements
nevets1219
@nevets1219: Thanks, you had beat me to it. :)
Anthony Forloney
+1  A: 

Here is a good site to remember these

As Anthony says for the actual examples

Romain Hippeau
+2  A: 

In the top diagram, the arrows indicate an association. This means that a Customer can have many Orders, and an Order can have one Customer. Since there is an arrowhead at each end, it means that the relationship is "bi-directional" meaning that each class has a reference to the other (each class "knows about" the other).

The corresponding classes might look like this:

public class Order
{
    public Customer Customer {get;set;}
    // Other order properties
}

public class Customer
{
    public List<Order> Orders {get;set;}
    // Other Customer properties
}

In the second diagram, the filled diamond represents "Composition." This is a more specific type of a relationship. Composition is usually compared to "aggregation," which would be an open diamond.

With the filled diamond (composition), it means that an Order has a "strong life-cycle" dependency on the Customer class. A common way of understanding Composition is saying that one class "owns" another. In this case, you would say that the Order "owns" the Customer, which doesn't really make sense, so I think it might be a bad example. Really, it's the Customer that should own the Order, so I think the filled diamond should be on the other side of the relationship.

Andy White