My question is that how Boolean as data type is defined so that it has the operation of equality? Does it have any attributes? How the operands are shown?
I want to use a similar concept for defining a new datatype that its operation is to sum the value of attributes for two instances of a class.
So I have a class which the type of one of its attributes is a data type that I have defined.
This data type has the operation of addition. But I don't know how this operation can be defined while this data type does not have any specific attributes.
DataTypes are opaque values and so a Date has an obvious value that may
be partitioned into smaller values. How it is implemented is not relevant.
DataTypes cannot be instantiated so they are always compared by deep
equality of value, whereas Classes are compared (in OCL) by object
In UML you can define operations for DataTypes and in OCL you can define
additional operations for DataTypes.
In order for an addition operator to be meaningful there needs to be
agreement on how 'add' is spelled. Since UML supports arbitrary names
'+' is obvious but it doesn't convert to Java so other names have been
used and I think the OCL UML/Ecore support looks for 'add'. Then there
is the problem of the argument type; is it polymorphic or not. Eclipse
OCL adds the polymorphic type OclSelf to repeat the source type. As
specification get firmer hopefully XXXX::_'+'(OclSelf) will standardize;
_'xxxx' is the OCL escape for names with awkward characters.
In the case of Date, you could implement all your operations by
delegating to java.lang.Date and so need no detailed attributes.
For your own type if you actually implement then you need attributes, so
you could delegate to a Class, or use a Class in the first place.
On 30/05/2014 22:11, Jeni Martin wrote:
> My question is that how Boolean as data type is defined so that it has
> the operation of equality? Does it have any attributes? How the
> operands are shown?
> I want to use a similar concept for defining a new datatype that its
> operation is to sum the value of attributes for two instances of a class.
> So I have a class which the type of one of its attributes is a data
> type that I have defined.
> This data type has the operation of addition. But I don't know how
> this operation can be defined while this data type does not have any
> specific attributes.
> Thank you very much,
Thank you very much for your reply. But I am not sure if I got it. Maybe I have asked wrongly. Suppose in a profile, I have defined two stereotypes (A and B) that extend the metaclass "Class". They both have an attribute called "a" and "b". Now, for instances of Stereotype A, I want to add the the values of attribute "a" altogether, while for any instances of stereotype B, I want to take the maximum of attribute "b" among them.
I thought maybe one solution is to define two different Data types for the type of "a" and "b" that each have their own operations. But I don't know how to define their operations while they don't have specific attributes. If I want to do it in a uml profile, How should I do that?