Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 982
Tilman Zuckmantel Avatar asked Mar 01 '23 22:03

Tilman Zuckmantel


2 Answers

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

like image 83
bruno Avatar answered Mar 11 '23 21:03

bruno


If you think about it, what you ask is unreasonable.

Suppose your system already has the over-enthusiastic constraint that a Car's FuelType is PETROL. You are in big trouble trying to define a derived Car whose FuelType is DIESEL; it would not be a Car wrt to the modelled definition of Car.

You could try to workaround the problem with mixins, but the number of permutations would be intolerable for any practical production Car.

Instead you can take the approach of loopholes adopted by the UML specification exemplified by the Namespace.isDistinguishable helper that determines whether unique names are required or not (multiple unnamed Constraints are permitted).

Therefore for Car you could define the getAcceptableFuelTypes() helper that can be overridden to create a loophole for derived classes; implement your base constraint as getAcceptableFuelTypes()->includes(fuelType).

like image 34
Ed Willink Avatar answered Mar 11 '23 21:03

Ed Willink