Constraints on extended stereotype in UML profile

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 :

  • in your proposal you suppose only your stereotype is named Car among all the stereotypes of all the profiles, of course that can be false. You can also check the name of the profile and may be its URI like:

    self.stereotype.name='Car'
    and self.stereotype.profile.name='Cars'
    -- and self.stereotype.profile.URI= '...'
    
  • in your diagram the arrow head is wrong because it must be a filled triangle rather than < (probably you use PlantUML) :

enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top