1

I'm not sure of the proper nomenclature to describe my question, so let me just jump into an example. Let's say that we're modeling a scenario where:

  • A Vendor can have multiple Customers
  • A Vendor can have multiple Employees
  • An Employee may only do work for one of the Vendor's Customers
  • An Employee's only relationship with a Customer is via the Vendor

For simplicity, let's ignore the myriad other real-world employment scenarios, and just say that there are contractual reasons for those last two constraints (e.g. protect intellectual property, non-compete).

Based on my meager UML skills, I'd be inclined to model these relationships as shown in the diagram below, which I believe is incorrect:

Incorrect UML class diagram

Specifically, I think that this diagram allows for an Employee to do work for many of the Customers, which violates the third constraint listed above. My question is:

  • What is the proper way to depict the constraint that an Employee may only be associated with one of the Customers?

Thank you in advance for your help.

[UPDATE]

Based on answers/comments, I'm including an updated example of a diagram that I believe to be more correct:

Proposed correct UML class diagram

Note the new relationship directly from Employee to Customer, which shows the cardinality from the third bullet above.

This still does not clearly convey that the Employee interacts with the Customer only by virtue of the Vendor; to me, the Employee could have a day job with Vendor, and be moonlighting with Customer. A comment on this post suggests adding an annotation to clarify.

2
  • In the context of analysis, design discussion, and documentation, UML is just meant to communicate ideas; it's meant for other humans, you are not going to use as an input to a tool to generate code from it. So the simplest thing you can do is attach a note box to the Vendor class, and write something like "Vendor makes sure there's a 1-1 relationship between Employees and Customers". Commented Jul 14, 2021 at 8:24
  • @FilipMilovanović Good suggestion; that will suffice for my current task. During my introduction to UML in the early 2000s, though, we did feed UML diagrams to a software tool that would yield a relational database schema. I can't recall if we ever modeled this specific condition, but I'd hope that there is some "official" way in UML to unambiguously depict the relationship in this example, such that a tool could generate the proper database objects.
    – manniongeo
    Commented Jul 14, 2021 at 21:49

1 Answer 1

1

An Employee's only relationship with a Customer is via the Vendor.

Don't confuse a real-world "relationship" with a data model "relationship." Those are two different things. An employee has a "does work for" data model relationship with a customer. Whether that work only flows through the vendor doesn't matter to the data model.

2
  • 1
    That makes sense. Two questions: 1) Should I add a new UML Association line between Employee and Customer with 1:1 cardinality and, if so, 2) would the existing Associations from the original diagram still imply that an Employee could do work for multiple Customers?
    – manniongeo
    Commented Jul 13, 2021 at 18:43
  • The way I read this, I would say no to question 2: There is no "conflict" between a 1..1 association from employee to customer, and the 0..* from vendor to customer. Each of these associations states something about the direct relationship between the directly connected entities, and nothing about their relationships via some other third entity (i.e. Employee --(1..1)--> Vendor --(0..*)--> Customer is not equivalent to, and should not be read as Employee --(0..*)--> Customer, if that makes any sense...).
    – Kjartan
    Commented Jul 13, 2021 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.