1

I'm a little confused on what the relationship would be for the scenario below. When examples of composition are used they always tend to use simple ones such as rooms and a building.

This scenario is that doctor patient visits are recorded. Would it be an association, composition or a mix of both? I've included a picture below of the two different relationships I am stuck between. I am thinking composition because the visit belongs to each party?

enter image description here

Derived association

  • 2
    See https://stackoverflow.com/questions/48268986/is-correct-relationships-of-class-diagram-in-uml though both answers had down votes :-/ I would not give a different answer here. – qwerty_so Jan 16 '18 at 17:07
  • @ThomasKilian so you would suggest EX.1 (obviously with multiplicities). Am I right in thinking that I cannot use the dash notation as that is used when there is only a single instance of the class and that is not the case with visit as there can be multiple visits? –  Jan 16 '18 at 17:26
  • 1
    Indeed I'd use an association class as suggested in one answer. – qwerty_so Jan 16 '18 at 21:14
  • Possible duplicate of [What is the difference between association, aggregation and composition?](https://stackoverflow.com/questions/885937/what-is-the-difference-between-association-aggregation-and-composition) – Geert Bellekens Jan 17 '18 at 05:55
  • Hey, the model below is not logical, as a visit cannot be simulatneously composite parts of (wholly within) doctor and also patient. You could use a shared aggregate (white diamond). But, in this scenario I’d model as a basic association since no form of aggregation makes sense given the common-sense definitions of doctor, visit and patient (if that’s what they are). – muszeo Jan 22 '18 at 06:24

2 Answers2

2

In general my rule of thumb is that when in doubt, always use association rather than composition/aggregation. My reasons for this are:

(1) In Object-oriented analysis and design for information systems Wazlawick notes that the real advantage of composition and aggregation is that the attributes of the parts are often used to derive attributes of the whole. As an example he mentions that the total value of an order (whole) is derived of the value of each of its items (parts). However, this to him is a design concern rather than a conceptual modelling concern. From a conceptual modelling perspective, he believes that modellers often apply aggregation and composition inappropriately (that is, where whole-part relations are not present) and that their use seldom have real benefit. Hence he suggests avoiding or even abolishing their use.

(2) UML aims to provide a semi-formalization of part-whole relations through composition/aggregation. However, formalization of part-whole relations is a non-trivial task, which the UML specification does not do justice. Indeed, a number of researchers have pointed out various aspects with regards to aggregation and composition in which the UML specification is under specified. All have proposed means for addressing the shortcomings of the UML specification, but to date these changes have not been incorporated into the UML specification. See for instance Introduction to part-whole relations.

Henriette Harmse
  • 4,167
  • 1
  • 13
  • 22
  • Is there a tl;dr for the last paper you mention :-? Seems to confirm my "Aggregation is evil" thesis. – qwerty_so Jan 16 '18 at 21:12
  • Not what I am aware of. lt is not just aggregation, it is also composition. It all becomes muddled when considering transitive part-whole relations. – Henriette Harmse Jan 16 '18 at 23:58
  • Yeah. On a first look this looks trivial. But when it comes to the nitty gritty you better be on holidays ;-) – qwerty_so Jan 17 '18 at 00:04
1

When being in doubt, which kind of associoation to use, use the more generic one. Especially, in your case there is no real "consists of" relation. Further in your EX2, you would have an instance of visit, which is an existance bound instance to an Doctor instance and to Patient instance. This is problem when applying the composition rules, as it also introduces an existence relation between Doctor and Patien implicitely. Thus, this shall not be done.

I guess the concept you are loooking for is an association class. This is a class, which instances give the association between an Doctor instance and Patient instance some further information.

sim
  • 1,148
  • 2
  • 9
  • 18