2

I don't quite understand what {subset} stands for when it comes to the association between class diagrams in UML. I've found this PDF that talks about it on page 4: https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.138.5537&rep=rep1&type=pdf. Here is the diagram & text that you can also find on page 4:

enter image description here

I read this and I'm not 100% about what {subsets < class > } is about. It says that "The slot representing d will be a subset of the slot representing b. Elements of type B can be inserted into slot b and elements of type D can be inserted into slots b and d." So, is {subset} some kind of polymorphism ? I think that thorugh "slot" they mean like the argument of a method that is of type B. And because D subsets b that means that D is like the sub-class of b so it can be passed down as "b" in arguments because of Polymorphism.

So the question is : What is {subsets < class > } exactly, is it representing a sub class ?

On top of that I have other questions: What are {union}, {redefines < class > }, {nonunique} & {sequence}. What do does stand for ?

Some examples in code would make it easier to understand.

David
  • 624
  • 1
  • 6
  • 21
  • 1
    Not directly related: this other SO question provided a concrete example of whats subset, redefines and association specialisation can help to solve: https://stackoverflow.com/questions/62973692/how-to-model-a-covariant-association-class-in-uml -in the answers and comments there are references to inspiring articles on this topic. – Christophe Mar 21 '21 at 09:08

1 Answers1

3

So the question is : What is {subsets < class > } exactly, is it representing a sub class ?

It is not {subsets < class >} but {subsets < property name >}

In the given diagram D is the only visible class specializing B, and if they are no other classes specializing B then all the instances of B are instances of D and then {subset b} is equal to b.

But having at least :

enter image description here

all the instances of B are not necessary instances of D (including of classes specializing D), this is why d only concerns a subset of the instances of B concerned by b.

In your diagram and mine the subsets are not really useful, but there are for instance in case of redefinition e.g. {subsets a, redefines a} {subsets b, redefines b}


What are {union}, {redefines < class > }, {nonunique} & {sequence}

referring to formal/2017-12-05 §9.5.4 page 113 and 114 :

  • union means that the property is a derived union of its subsets.

  • nonunique: means that there may be duplicates in a multi-valued property. This is the opposite of unique meaning there is no possible duplicates. For instance supposing b is {nonunique} then some instances of B can be present several times in b. If the property is implemented in C++ by a std::set it is {unique}.

  • sequence means that the property represents an ordered bag, this is a shortcut of {nonunique, ordered}. This is the case of std::vector and std::list in C++.

  • {redefines < property-name > } (not {redefines < class >}) means that the property redefines an inherited property identified by < property-name >. If in your diagram the {subsets b} is replaced by {redefines b} then the classes C only has the slot (e.g. attribute in C++ etc) d. This is not like having b private so not accessible from C, that really means d is a redefinition of b.

bruno
  • 32,421
  • 7
  • 25
  • 37
  • Thank you for the answer but do you have any examples where {subsets property-name} could be used in code ? – David Mar 28 '21 at 12:04
  • 1
    @David you can have code directly inspired from my class diagram, class A has attribute *b* of type B, class B has attribute *a* of type A, class C inheriting A has attribute *d* of type D, and class D inheriting B has attribute *c* of type C. – bruno Mar 28 '21 at 12:38
  • yes, but what about {subset property-name}. What you wrote was just about property association but not property subsetting. What I don't understand is what exactly {subsets property-name} is, what's the role of writing {subsets a} right under the c property ? – David Apr 23 '21 at 16:21
  • On top of that, I have seen that we can also write {subsets association-end}. What exactly is meant with association-end. Is the association-end and property-name the same thing ? – David Apr 23 '21 at 16:24
  • Is {subsets property-name} directed towards the class or the property. Do you mean by any chance that {subsets b}, under d, in this case means that you can use polymorphism in some cases since the class D is specializing the class B and pass it as type B in methods where the argument type needed is B ? – David Apr 23 '21 at 16:30