Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » UML-OCL : Inheriting operations from primitive types in standard UML library
UML-OCL : Inheriting operations from primitive types in standard UML library [message #1719412] Thu, 07 January 2016 17:25 Go to next message
German Vega is currently offline German VegaFriend
Messages: 51
Registered: December 2015
Member
Hello

I am trying to create my own Primitive Types by inheriting from the ones defined in standard UML Primitive Types Library. Then I use my defined types to define the properties of my classes. This seems to be accepted by UML, as I don't have any validation errors.

see attached image, for a small example.

index.php/fa/24531/0/

The problem arises when I write OCL constraints that uses these properties. If the type of my property is one in the standard UML library (say Unlimited Natural) I can use operators defined in the standard OCL library ( <, + , ...) . However, if the type of the property is my own defined Primitive type I get a parsing error, because the operation is not defined for my type.

Digging the code of the UML2Pivot transformation, I have managed to pinpoint that the problem is the generalization hierarchy is only copied from the UML model to the OCL Pivot model in these two cases :
- for Classes (in UML2PivotReferenceSwitch.caseClass()
- for interfaces (in UML2PivotUseSwitch.caseInterface()

But the generalization hierarchy is never copied for PrimitiveTypes.

In the UML metamodel the generalization hierarchy is defined in class Classifier (property generalizations). In the OCL Pivot metamodel the generalization hierarchy is defined in class Type (property superClass).

In UML ,PrimitiveType inherits indirectly from Classifier. In OCL Pivot , PrimitiveType inherits indirectly from Type. So, in principle, it may be possible to recreate the hierarchy.

So the question is whether my usecase is a valid? is it worthwhile to try to make this work (as from my initial investigations seems to be possible)? or it is just a corner case of UML/OCL that will lead to unanticipated problems,

[Updated on: Thu, 07 January 2016 17:35]

Report message to a moderator

Re: UML-OCL : Inheriting operations from primitive types in standard UML library [message #1719416 is a reply to message #1719412] Thu, 07 January 2016 18:25 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

PrimitiveTypes are primitive so I cannot recommend extending them.

In order to make PrimitiveType an extensible concept for use with OCL,
the OCLforUML profile defines <<Integer>>, <<Real>> and other
stereotypes that can be applied to your DataTypes. See
http://www.slideshare.net/EdWillink/the-oclforuml-profile

Unfortunately the profile lacks the extra Papyrus registration in Mars,
so you may need to use the UML Model editor to apply it. Recent versions
of Papyrus have the extra registration.

Regards

Ed Willink


On 07/01/2016 17:25, German Vega wrote:
> Hello
>
> I am trying to create my own Primitive Types by inheriting from the ones defined in standard UML Primitive Types Library. Then I use my defined types to define the properties of my classes. This seems to be accepted by UML, as I don't have any validation errors.
>
> see attached image, for a small example.
>
>
>
> The problem arises when I write OCL constraints that uses these properties. If the type of my property is one in the standard UML library (say Unlimited Natural) I can use operators defined in the standard OCL library ( <, + , ...) . However, if the type of the property is my own defined Primitive type I get a parsing error, because the operation is not defined for my type.
>
> Digging the code of the UML2Pivot transformation, I have managed to pinpoint that the problem is the generalization hierarchy is only copied from the UML model to the OCL Pivot model in these two cases :
> - for Classes (in UML2PivotReferenceSwitch.caseClass()
> - for interfaces (in UML2PivotUseSwitch.caseInterface()
>
> But the generalization hierarchy is never copied for PrimitiveTypes.
>
> In the UML metamodel the generalization hierarchy is defined in class Classifier (property generalizations). In the OCL Pivot metamodel the generalization hierarchy is defined in class Type (property superClass).
>
> In UML ,PrimitiveType inherits indirectly from Classifier. In OCL Pivot , PrimitiveType inherits indirectly from Type. So, in principle, it may be possible to recreate the hierarchy.
>
> So the question is whether my usecase is a valid? is it worthwhile to try to make this work (as from my initial investigations seems to be possible)? or it is just a corner case of UML/OCL that will lead to unanticipated problems,
>
>
Re: UML-OCL : Inheriting operations from primitive types in standard UML library [message #1719479 is a reply to message #1719416] Fri, 08 January 2016 09:58 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 885
Registered: February 2011
Senior Member
Hi,

Quote:
Unfortunately the profile lacks the extra Papyrus registration in Mars,
so you may need to use the UML Model editor to apply it. Recent versions
of Papyrus have the extra registration.


It has been added to Papyrus Mars after 1.1.3 (The current release), so it is available in the Nightly builds only. It will be officially released with Mars SR2 in February

Camille


Camille Letavernier
Re: UML-OCL : Inheriting operations from primitive types in standard UML library [message #1719496 is a reply to message #1719416] Fri, 08 January 2016 11:33 Go to previous messageGo to next message
German Vega is currently offline German VegaFriend
Messages: 51
Registered: December 2015
Member
Hi,

Thanks Ed for your prompt response,

Quote:

PrimitiveTypes are primitive so I cannot recommend extending them.

In order to make PrimitiveType an extensible concept for use with OCL,
the OCLforUML profile defines <<Integer>>, <<Real>> and other
stereotypes that can be applied to your DataTypes


Certainly this helps solve many of my problems, specially for unstructured data types.

For structured data types however, I have found similar problems (see attached image):

index.php/fa/24545/0/

Using properties defined in DataTypes in OCL constraints works, but they are not inherited. For query Operations (defined or inherited) of DataTypes, they are not translated to the pivot model.

Just for context, I am working on a tool that semi-automatically translates UML/OCL models to the formal Z notation, for model animation and proof. The difference between classes and datatype is important in the translation as I use different semantics (value or reference equality for instance) in each case.

In general, I think that many cases in the UML2Pivot transformation that are currently restricted to Classes could be also be handled for DataTypes. But I am not an OCL expert, and it seems to be subtle differences between an OCL DataType and an UML DataType. If you consider that is worth working on this, I can contribute my time to help with the development.

By the way, I have been testing with the Luna release, so I will install Mars and check if I have the same problems.

In all cases, thanks for this great tooling.

[Updated on: Fri, 08 January 2016 11:36]

Report message to a moderator

Re: UML-OCL : Inheriting operations from primitive types in standard UML library [message #1719531 is a reply to message #1719496] Fri, 08 January 2016 16:36 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

Insightful help is very welcome.

Rather too much of my UML knwoledge was derived from the UML < 2.4 Basic
Package which was much more restrictive. I've gradually relxed
inappropriate restrictions.

I think you'll find that DataType inheritance is fixed by commit
"[472469] Convert DataType generals to superclasses in UML2AS" in Mars.1.

UML2Pivot is now UML2AS and is hopefully going to move from ad hoc
manual Java code to an OCL-defined autogenerated Java code shortly.

Regards

Ed Willink


On 08/01/2016 11:33, German Vega wrote:
> Hi,
>
> Thanks Ed for your prompt response,
>
> Quote:
>> PrimitiveTypes are primitive so I cannot recommend extending them.
>>
>> In order to make PrimitiveType an extensible concept for use with OCL,
>> the OCLforUML profile defines <<Integer>>, <<Real>> and other
>> stereotypes that can be applied to your DataTypes
>
> Certainly this helps solve many of my problems, specially for unstructured data types.
>
> For structured data types however, I have found similar problems (see attached image):
>
>
>
> Using properties defined DataTypes in OCL constraints works, but they are not inherited. For query Operations (defined or inherited) of DataTypes, they are not translated to the pivot model.
>
> Just for context, I am working on a tool that semi-automatically translates UML/OCL models to the formal Z notation, for model animation and proof. The difference between classes and datatype is important in the translation as I use different semantics (value or reference equality for instance) in each case.
>
> In general, I think that many cases in the UML2Pivot transformation that are currently restricted to Classes could be also be handled for DataTypes. But I am not an OCL expert, and it seems to be subtle differences between an OCL DataType and an UML DataType. If you consider that is worth working on this, I can contribute my time to help with the development.
>
> By the way, I have been testing with the Luna release, so I will install Mars and check if I have the same problems.
>
> In all cases, thanks for this great tooling.
Re: UML-OCL : Inheriting operations from primitive types in standard UML library [message #1719669 is a reply to message #1719531] Mon, 11 January 2016 09:37 Go to previous messageGo to next message
German Vega is currently offline German VegaFriend
Messages: 51
Registered: December 2015
Member
Hi Ed,

I've been making some tests with the Mars version, and many of the problems that I've been experiencing in Luna are already solved Smile and the OCLforUML profile really helps for numeric types.

I still have to understand some of the semantics of DataTypes in UML 2.5, particularly generalization, in order to complete the tool I've been working on. For example, I see that it is possible for an enumeration to generalize another enumeration adding literals, which make sense from a substituability point of view, but noy much from the inclusion of the instances sets. But that is beyond this forum Wink

Thanks for your help.
Re: UML-OCL : Inheriting operations from primitive types in standard UML library [message #1719673 is a reply to message #1719669] Mon, 11 January 2016 10:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

I am gradually concluding that there is only one real difference between
DataType and Class.

Two DataTypes are compared for equality by deep transitive content
comparison.

Two Classes are compared for equality by identity (memory address in a
practical implementation).

All other differences seem to be specification accidents.

Regards

Ed Willink


On 11/01/2016 09:37, German Vega wrote:
> Hi Ed,
>
> I've been making some tests with the Mars version, and many of the
> problems that I've been experiencing in Luna are already solved :) and
> the OCLforUML profile really helps for numeric types.
> I still have to understand some of the semantics of DataTypes in UML
> 2.5, particularly generalization, in order to complete the tool I've
> been working on. For example, I see that it is possible for an
> enumeration to generalize another enumeration adding literals, which
> make sense from a substituability point of view, but noy much from
> the inclusion of the instances sets. But that is beyond this forum ;)
>
> Thanks for your help.
Re: UML-OCL : Inheriting operations from primitive types in standard UML library [message #1719682 is a reply to message #1719673] Mon, 11 January 2016 12:54 Go to previous messageGo to next message
German Vega is currently offline German VegaFriend
Messages: 51
Registered: December 2015
Member
Hi Ed,

Quote:

I am gradually concluding that there is only one real difference between
DataType and Class.

Two DataTypes are compared for equality by deep transitive content comparison.Two Classes are compared for equality by identity (memory address in a practical implementation).

All other differences seem to be specification accidents.


Well, I came more or less to the same conclusion, but then the interaction with other features of the language is not clear to me.

What does it mean for example an association between a Class and a structured DataType ? if I only consider the direction Class towards DataType I could imagine that the data of the DataType could be embedded by value in the slots of object, like is the case for primitive properties. But then, what if several objects reference the "same" instance of the data type, should the data be duplicated? and if I change a referenced instance of the datatype, should I update all objects that embed the "same" instance or simply update the copy used by the update action ? does it makes sense DataType.allInstances() ? and my doubts go on and on.

Perhaps I should consider DataTypes simply like C# structs for example, and impose some restrictions: C# doesn't not allow inheritance for example, or avoid cycles of DataType associations (which means DataTypes are mainly used to model hierarchical by-value data structures, much like an XML document without XLinks).

I suppose the UML specification is purposely vague regarding the semantics (other than by-value equality) to allow several interpretations depending on the intended usage of the model. Do you know if the Action Language or fUML provides a more concrete specification of the semantics of DataTypes?

In any case, thank you for your comments, this conversation is very helpful for me.




Re: UML-OCL : Inheriting operations from primitive types in standard UML library [message #1719685 is a reply to message #1719682] Mon, 11 January 2016 13:08 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
HI

IMHO there are no instances of DataTypes, just DataType values, so the
DataType value may be embedded in a Class, it cannot be dijoin or
modelled as shared.

cf. Ecore. An EReference can only be to an EClass. An EAttribute only of
an EDataType.

Regards

Ed Willink


On 11/01/2016 12:54, German Vega wrote:
> Hi Ed,
>
> Quote:
>> I am gradually concluding that there is only one real difference between
>> DataType and Class.
>>
>> Two DataTypes are compared for equality by deep transitive content
>> comparison.Two Classes are compared for equality by identity (memory
>> address in a practical implementation).
>>
>> All other differences seem to be specification accidents.
>
>
> Well, I came more or less to the same conclusion, but then the
> interaction with other features of the language is not clear to me.
>
> What does it mean for example an association between a Class and a
> structured DataType ? if I only consider the direction Class towards
> DataType I could imagine that the data of the DataType could be
> embedded by value in the slots of object, like is the case for
> primitive properties. But then, what if several objects reference the
> "same" instance of the data type, should the data be duplicated? and
> if I change a referenced instance of the datatype, should I update all
> objects that embed the "same" instance or simply update the copy used
> by the update action ? does it makes sense DataType.allInstances() ?
> and my doubts go on and on.
>
> Perhaps I should consider DataTypes simply like C# structs for
> example, and impose some restrictions: C# doesn't not allow
> inheritance for example, or avoid cycles of DataType associations
> (which means DataTypes are mainly used to model hierarchical by-value
> data structures, much like an XML document without XLinks).
>
> I suppose the UML specification is purposely vague regarding the
> semantics (other than by-value equality) to allow several
> interpretations depending on the intended usage of the model. Do you
> know if the Action Language or fUML provides a more concrete
> specification of the semantics of DataTypes?
>
> In any case, thank you for your comments, this conversation is very
> helpful for me.
>
>
>
>
>
Re: UML-OCL : Inheriting operations from primitive types in standard UML library [message #1719689 is a reply to message #1719685] Mon, 11 January 2016 13:31 Go to previous message
German Vega is currently offline German VegaFriend
Messages: 51
Registered: December 2015
Member
Hello

Quote:
IMHO there are no instances of DataTypes, just DataType values


Yes, I suppose is better to keep things simple

Than you for your time.
Previous Topic:Executing "ClassName.allInstances()" query on instances created using InstanceSpecificatio
Next Topic:Unresolvable property on class with exactly one association
Goto Forum:
  


Current Time: Sat Sep 22 03:25:30 GMT 2018

Powered by FUDForum. Page generated in 0.02140 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top