Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to model a mixin in UML

Tags:

mixins

uml

What is the best way to represent a "mixin" using UML?

As documented in this article:

In object-oriented programming languages, a mixin refers to a defined amount of functionality which can be added to a class. An important aspect of this is that it makes it possible to concentrate more on the properties of a particular behaviour than on the inheritance structures during development.

I will give more details about my particular use case. I have a collection of classes that model different types of objects. Because all of them can be stored on a storage, I want to use a mixin to implement all the functionality related to "being stored". Of course, I can use abstract classes but I do not like it because these classes should be part of a different hierarchy of classes and the fact that they can be stored is only a secondary property. Another option can be to use composition and add the "storage node" as a field of this classes. I do not like this option either for the same reason: I do not want to create any dependency between the classes and the storage.

I have already implemented the solution in Java using a mixin based on dynamic proxies and I would like to document the solution with a clear UML class diagram. Is there a standard way to represent this mixin?

I am also wondering whether it is a good idea to model also how the mixin has been implemented (using proxies) or it is better to use a more abstract representation.

Thanks

like image 929
Marco Altieri Avatar asked Sep 19 '25 18:09

Marco Altieri


1 Answers

Actually there are many ways to model this in UML:

One approach could be to stereotype the operations and properties with <<mixin>> or the like and then use tagged values to describe where you got them from.

Another (I'd prefer) is to actually use a <<mixin>> stereotyped Generalization and attach a note to that telling which operations/properties should be mixed. That would give the implementer a guide to just "lean implementation of the general class".

Eventually you could create <<mixin>> sub-classes with subsets of the ops/props you want to mix in the final class and then Generalize from those.

Probably one could come up with more solutions. Use an approach which suits you best. There is not generic mixin pattern in UML (to my knowledge).

like image 63
qwerty_so Avatar answered Sep 21 '25 21:09

qwerty_so