umloclstereotype

Constraints on extended stereotype in UML profile


Suppose you have an excerpt of a larger profile for cars:

Profile Excerpt for Cars

Now i want to define some constraints for a Car, say one of those constraints states, that if attrA is true, then attrB must be false like this using OCL:

Context UML::Core::Class inv:
self
  .stereotype
  .name='Car'
implies
  self.attrA=true
  implies
    self.attrB=false

My question is: If the Mercedes stereotype specializes the Car stereotype do I stick to the same constraints, in other words: is the stereotype Car still applied for classes that have the Mercedes stereotype applied?

I would suppose that self.stereotype.name='Car' return false if the applied stereotype is Mercedes.

This is interesting because I want to have the same attributes on a Mercedes as on a Car, but i want to change the previously stated constraint.


Solution

  • I would suppose that self.stereotype.name='Car' return false if the applied stereotype is Mercedes.

    Yes you are right.

    Mercedes inherits the constraint as it is, so self.stereotype.name='Car' is false for a class stereotyped Mercedes rather than Car because 'Mercedes' and 'Car' are two different strings.


    If you want to have the first implies active for the metaclasses specializing Car directly or indirectly you can get all the generalizations of the stereotype more itself to search for one named 'Car', also checking the name of the profile of the stereotype and may be its URI. So for instance replace self.stereotype.name='Car' by :

    self.stereotype.profile.name = 'Cars' and
    -- self.stereotype.profile.URI= '...' and
    self.stereotype.generalization()
      ->closure(general.generalization).general()
        ->including(self.stereotype)
          ->select(name = 'Car')
            ->notEmpty()
    

    or with an alone profile named Cars and an alone stereotype in it named Car :

    self.stereotype.oclIsKindOf(Profile.allInstances()
                                  ->any(name = 'Cars') -- may be check also URI
                                     .ownedStereotype->any(name = 'Car'))
    

    Additional notes :

    enter image description here