0

The example is the following :

 -----------                -------------------- 
|     X     | 1..1    0..1 |    <<abstract>>    |
|           |<>------------|         Y          |
|-----------|              |--------------------|
| +a:bool   |              | +b:positiveInteger |
'-----------'              '--------------------'

In the real world, abstract Y can be a concrete A, B or C, according to the following rules :

  • when a is true, Y is an A class ;
  • when a is false and b == 1, Y is a B class ;
  • when a is false and b > 1, Y is a C class.

How would you modelize these rules of inheritance in an UML class diagram ?

Elvex
  • 656
  • 5
  • 22

1 Answers1

1

You can use the OCL langauge for this.

First you should extend your diagram and introduce the three concrete subclasses, A, B, and C of Y, then you need an OCL constraint like this:

context X:
inv: (self.a implies self.y isOclTypeOf(A)) and
     (((not self.a) and (not self.y.isOclUndefined())) implies (self.y.b = 1 implies self.y.isOclTypeOf(B))) and
     (((not self.a) and (not self.y.isOclUndefined())) implies (self.y.b > 1 implies self.y.isOclTypeOf(C)))
gefei
  • 18,922
  • 9
  • 50
  • 67
  • [Schematron](http://en.wikipedia.org/wiki/Schematron) seems to work as well, for XML documents. – Elvex Nov 26 '12 at 03:35