2

I'm currently studying software engineering patterns and one that we've been given to study is the "historical association pattern" It refers to the historical mapping pattern given in Fowler's "Analysis patterns" book. The example we've been given is as follows:

enter image description here

I've tried looking for information online on how this structure would be implemented but I've found nothing regarding historical mapping associations. What would be a code/pseudo-code example of this structure?

daniel
  • 118
  • 1
  • 7

1 Answers1

2

Short answer

This pattern consist simply of using some dates for an association, by the means of an association class.

Full explanation

The diamond in the middle is a ternary association between Employee, Date and Money. The dotted line says that the Salary is the association class and it is also associated with a Date.

The association class would be typically be implemented with tuples/composed classes of Employee, Date, Money and the Salary attributes. The way it is done can be very different: in Java you’d directly refer to the associated objects, whereas in a db you’d have a mix of ids and salary attributes. Much simpler than this impressive diagram.

There are simpler models for that!

This diagram is difficult to read (ternary association), difficult to understand (multiplicity in ternary associations are not obvious to grasp), ambiguous (i.e. is Salary associated with two dates, from the ternary association it represents and from the direct association? or is it just a graphical redundancy?).

It would be much simpler to understand if it would be refactored into a binary association, and if value objects such as Dare would be shown as attributes.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • 1
    Thanks. I honestly don't know why it's represented that way. It does seem like a long workaround for something that could be done in a simpler way, but it's included in the materials that were given to us by the university. – daniel Feb 26 '22 at 09:21
  • 1
    @daniel indeed. In fact, if taking UML semantics by the letter, this schema would mean that each Date has a distinct identity, independently of its value whereas dates are typically value objects that should be noted as datatype. Was the schema in Fowler’s book or in the university material? – Christophe Feb 26 '22 at 10:45
  • 4
    Yes, `Date` and `Money` should be datatypes. That doesn't mean that they cannot appear in an association. The ternary association here means, that for each pair of Employee and Date, there can only be one Money value. Expressing the same with binary associations makes it necessary to use constraints. So, there are good reasons for using a ternary association. Of course, not many people understand them, so it probably should be avoided. – Axel Scheithauer Feb 26 '22 at 11:55
  • It's in the university material and similar to fowler's example. The main difference is that Fowler uses a time period as the third class (Employee-TimePeriod-Money), so there's no association between the association class Salary and anything else. – daniel Feb 26 '22 at 12:02
  • 1
    What confuses me a bit about the university's example is the multiplicities. Thank you Axel for explaining the 0..1 in Money, but what do the other multiplicities express in the ternary association? For each pair Money-Date there can be multiple employees and for each pair Money-Employee there can be multiple Dates? – daniel Feb 26 '22 at 12:13
  • @AxelScheithauer I think your comment should go as answer as well... – qwerty_so Feb 26 '22 at 19:38