Book a Demo

Author Topic: Lozenge (tm) & OCL  (Read 9976 times)

SF_lt

  • EA User
  • **
  • Posts: 216
  • Karma: +1/-0
  • The Truth Is Out There
    • View Profile
Lozenge (tm) & OCL
« on: November 01, 2005, 10:34:52 am »
Always had hesitations about lozenge/N-association use. Particularly cases with several lozenge classes - how to decrypt this association: each with a rest?
For example: 4-nary lozenge: classA, classB, classC, classD & lozenge named LO. How this would be: classA-classB, classA-classC, classA-classD, classB-classC, ...., classC-classD ???

want/need deep clarification of this (pictures with normal associations and with lozenge - thanks in an advance)

Are these diagrams the same? It would be great to hear Paolo & other gurus :-D

1 (dependencies can be replaced by associations):


2:


Is it allowed to change association class cardinality? if channel  connects one sender and many receivers (UML way would be: one sender-one receiver for association class)? is 1 diagram correct for for multiple receivers of channel ? correct me, please, if I'm wrong
Not sure, if OCL size() invariant will be consistent with the UML metamodel

BTW, how to add operations/attributes to lozenge? somewhere Paolo showed, that 2-nary lozenge & association class is the same.

BTW2: how to add constraints for the association class - there is no constraint field ;)
registertm everything to SparX

thomaskilian

  • Guest
Re: Lozenge (tm) & OCL
« Reply #1 on: November 01, 2005, 01:09:23 pm »
I can't tell about your main question - the real gurus will answer soon, for sure. Concerning your en passant questions: I thought changing the element type to Class and back would help, but obviously there is a bug with the Lozenge Element Type (I reported to Sparx). And the 2nd one: I use 772 and there's a Constraints tab in the properties. Maybe cross-eyed ;)

jeshaw2

  • EA User
  • **
  • Posts: 701
  • Karma: +0/-0
  • I'm a Singleton, what pattern are you?
    • View Profile
Re: Lozenge (tm) & OCL
« Reply #2 on: November 01, 2005, 09:08:06 pm »
I'm confused.

In your first diagram, I don't see how the channel uses the signal.  I should think it the other way around; the signal uses the channel.  A road does not need the car, but a car may need a road.

Can you clarify your model by articulating what you believe it is saying?
Verbal Use Cases aren't worth the paper they are written upon.

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Lozenge (tm) & OCL
« Reply #3 on: November 01, 2005, 09:22:13 pm »
Just taking the first part of your question for now...

Quote
Always had hesitations about lozenge/N-association use. Particularly cases with several lozenge classes - how to decrypt this association: each with a rest?
For example: 4-nary lozenge: classA, classB, classC, classD & lozenge named LO. How this would be: classA-classB, classA-classC, classA-classD, classB-classC, ...., classC-classD ???


UML 2.0 states "For an association with N ends, choose any N-1 ends and associate specific instances with those ends. Then the collection of links of the association that refer to these specific instances will identify a collection of instances at the other end."

So it seems that your 4-nary lozenge will have one class at one end, and N-1=3 classes at the other end(s). So that might be classA-classB, classA-classC and classA-classD and nothing else, or the same with one of the other classes at the solo end.
The Sparx Team
[email protected]

SF_lt

  • EA User
  • **
  • Posts: 216
  • Karma: +1/-0
  • The Truth Is Out There
    • View Profile
Re: Lozenge (tm) & OCL
« Reply #4 on: November 02, 2005, 03:38:06 am »
KP, could you post diagram? ;)

I have read this superstructure sentence, but without example and explanation it doesn't help a lot
btw, if you choose other ends, you can get not classA with the left classes, but classC with the rest (classC-classA, classC-classB & etc)

Also, one little specification on constraints: what I miss, I miss feature to add constraint for the dotted line from association class to association line - there is no way to attach constraint or smth else to this part of association. Maybe UML2 metamodel prohibits it...

jeshaw, I agree, that road doesn't need to know, what cars use it (what about women? :-D )
in my example, channel passes signals from sender to receivers, also signals travel through the channel to reach their's destination. Also not all signals use one or other channel - there may be many channels.
But still, thanks for your point
« Last Edit: November 02, 2005, 04:59:16 am by SF_lt »
registertm everything to SparX

SF_lt

  • EA User
  • **
  • Posts: 216
  • Karma: +1/-0
  • The Truth Is Out There
    • View Profile
Re: Lozenge (tm) & OCL
« Reply #5 on: November 03, 2005, 01:15:13 am »

another thing: how with the OCL specify new variable for the class, which value can be NULL or object?

something like this (it's not a correct OCL statement)

context class
def: member: classB = ( NULL or classB_object )

how to specify classB type object?
registertm everything to SparX

raf952

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Lozenge (tm) & OCL
« Reply #6 on: November 03, 2005, 08:33:09 am »
Quote
Always had hesitations about lozenge/N-association use. Particularly cases with several lozenge classes - how to decrypt this association: each with a rest?
For example: 4-nary lozenge: classA, classB, classC, classD & lozenge named LO. How this would be: classA-classB, classA-classC, classA-classD, classB-classC, ...., classC-classD ???

want/need deep clarification of this (pictures with normal associations and with lozenge - thanks in an advance)

Are these diagrams the same? It would be great to hear Paolo & other gurus :-D

I'm not a guru--or if I am, I haven't gotten my club membership card yet... but here's my quick take.

In the first diagram there is a thingy that exists called a Channel--it could have state and behavior. Its definition is based on the relationship between a sender and a receiver, that is, you don't have a Channel without them.

In the second diagram "channel" is just the name given to the association. It doesn't have any state or behavior of it's own--there's no "channel id"... you can't ask it what's the current message volume over it; after all, "it" doesn't really exist. If those questions are valid, it's not clear what  part of the design is responsible for answering them.

I hope this helps.

I also hope it's accurate...  ;)

raf

P.S. What's a "lozenge" (besides a breath mint)?

mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: Lozenge (tm) & OCL
« Reply #7 on: November 03, 2005, 09:01:41 am »
Perhaps you should ask "why do they make breath mints in the shape of a lozenge?" ... it's a rhombus/"diamond ◊" shape

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Lozenge (tm) & OCL
« Reply #8 on: November 03, 2005, 03:23:20 pm »
Quote
KP, could you post diagram? ;)

I have read this superstructure sentence, but without example and explanation it doesn't help a lot
BTW, if you choose other ends, you can get not classA with the left classes, but classC with the rest (classC-classA, classC-classB & etc)
Hi SF_lt (can we have a more human moniker for you? :) ),

If you are familiar with ERD or DB design, the best way to think about the Lozenge (in my view) is as an Intersector Table, with a mandatory, singular, foreign key to each of the associated Classes (as Tables).  Therefore the UML statement KP (another non-human? :) ) quoted merely states that if you run a query over the lozenge where you supply values for each of the foreign keys but one, you'll get the set of rows where the value of the remaining foreign key varies.  The quote goes on to say that if the end is ordered or unique, this will apply the same constraints on the set of values returned by the query.  Does that help?
Quote
Also, one little specification on constraints: what I miss, I miss feature to add constraint for the dotted line from association class to association line - there is no way to attach constraint or smth else to this part of association. Maybe UML2 metamodel prohibits it...
The dotted line is not a real connector.  It is merely trying to reinforce the idea that the Association Class IS the Association line.  It is a rendering artifact, not a real UML element.  Therefore you can't attach any metadata to it.  That's why Thomas said use the Constraints tab on the AssociationClass or Lozenge.

FWIW, I can't reinforce enough that Sparx needs to understand that the lozenge shape is merely a rendering of the AssociationClass (like say the Boundary, Control and Entity shapes from the Analysis toolkit).  Also, that the AssociationClass defined by UML is merely binary example of the N-ary Association.  So a binary Association may be depicted by an Association line by itself, an Association line with associated AssociationClass or an Association lozenge with two AssociationEnds - they are all the same thing!

Accordingly, you should be able to do everything you can do to a Class to the Lozenge!

Quote
jeshaw, I agree, that road doesn't need to know, what cars use it (what about women? :-D )
in my example, channel passes signals from sender to receivers, also signals travel through the channel to reach their's destination. Also not all signals use one or other channel - there may be many channels.
But still, thanks for your point
By Signal here, do you mean Signal Type?  If you mean Signal, what is the domain identifier that allows you to specify which signal instance you are associating.  From my intersector table example above, you'll see you need to provide the foreign key to identify each AssociationEnd.  IF you can't find one, then it's an indication the model is wrong.

It strikes me that this would be a good example to work through for AssociationClasses and lozenges etc.  Like Jim, I'm not so sure there is an N-ary relationship here.

To determine how to model the rules, we need to know the rules.  Could you give us a short definition of each of the Classes involved:  Sender, Receiver, Channel and Signal?  Without them, we can't really provide the direction you are seeking.  Nothing fancy (as they say in the competitions - 25 words or less ;D)

If you've been following some of my postings, you'll see I strongly favour a technique called "Verbalisation" - where you "speak out" the model.  If the words sound wrong, the model is wrong!

HTH,

Paolo
[size=0]©2005 Paolo Cantoni, -Semantica-[/size]
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Lozenge (tm) & OCL
« Reply #9 on: November 03, 2005, 05:03:16 pm »
Quote
FWIW, I can't reinforce enough that Sparx needs to understand that the lozenge shape is merely a rendering of the AssociationClass
It's a rendering of Kernel::Association which doesn't specialize Kernel::Class. Without the Class properties an Association can't be called an AssociationClass.

Quote
Also, that the AssociationClass defined by UML is merely binary example of the N-ary Association.
with the addition of properties inherited from Kernel::Class.

Quote
So a binary Association may be depicted by an Association line by itself, an Association line with associated AssociationClass or an Association lozenge with two AssociationEnds - they are all the same thing!
No, two of those are Associations, one is an AssociationClass.

EDIT: On thinking things through, you are free to model all associations as AssociationClass if you wish - it is, after all, adding extra information to the model not subtracting, and if you need the extra info then why not? So to answer your original point, Sparx don't "need to understand that the lozenge shape is merely a rendering of the AssociationClass" but we need to allow you to understand that. I think.

Neil

PS "KP" is pronounced the same as my surname and is easier to type. I've always used it on message boards. In the UK it's also a brand of nut  :-/
« Last Edit: November 03, 2005, 05:35:40 pm by KP »
The Sparx Team
[email protected]

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Lozenge (tm) & OCL
« Reply #10 on: November 04, 2005, 03:21:12 pm »
Quote
[size=13][SNIP][/size]
EDIT: On thinking things through, you are free to model all associations as AssociationClass if you wish - it is, after all, adding extra information to the model not subtracting, and if you need the extra info then why not? So to answer your original point, Sparx don't "need to understand that the lozenge shape is merely a rendering of the AssociationClass" but we need to allow you to understand that. I think.

Neil

PS "KP" is pronounced the same as my surname and is easier to type. I've always used it on message boards. In the UK it's also a brand of nut  :-/
Hi Neil,

Thanks for the edit.  There's hope for you yet. ;D

You're half way there...  The problem with the Association Class is that as manifest (on OMG Diagrams etc) it appears to apply only to a binary relation.  This can't possibly be the case!  We have a continuum of (outbound, N-ary) AssociationEnds for an AssociationClass from 2 upward.  Similarly, we have a continuum of AssociationClass Features from N (one attribute for each (N-ary) AssociationEnd) upward.  

Accordingly, If I can represent a binary Association as either:
  • a single Association line (which is composed of the two AssociationEnds) between the two Associated Classes
  • or a line with the (rendered) attached AssociationClass
  • or the Association lozenge and the two AssociationEnds
then it is obvious (at least to me on a few minutes thought) that the lozenge IS the AssociationClass!

If this is so, the we have an elegant proof that is then extensible to the N-ary case!  In short, it works!

Now all we need is for Sparx to provide the additional context menu item on the AssociationClass (which IS the Lozenge) ("Use Lozenge Notation") (similar to the "Use Circle Notation" for an Interface) to allow us to switch between renderings and we're sweet!).

BTW: I don't know how many of you have been bothered by the question "What makes an AssociationClass different from an ordinary Class?"

Do you (the reader - not just Neil!) know?  Have you thought about it?  Will it come up as a question on the OMG Certification Exam?

An AssociationClass is a Class that represents an Association and thus has one required attribute referencing the associated Class for each arity of the N-ary Association it represents.  Add/Remove an AssociationEnd and the attribute is accordingly added/removed.

It all works!

So, Neil, when do we get the "Use Lozenge Notation" context menu Item?  Or at a minimum, the ability to change the Type of the Lozenge from Association to Class and back; as I think has been requested before in the forum?

Pleadingly,
Paolo

BTW: The UML specifications are either somewhat compressed and potentially confusing or, in at least one place, downright incorrect on the subject of the N-ary Association.  In particular, Figure 74 of the the UML 2 [size=13]Infrastructure[/size] Specification showing Binary and ternary Association is incorrect in the placement of the multiplicities.  The multiplicity of the each AssociationEnd with respect to the associated Class is one!  The N-ary Association is defined as a Tuple and therefore the multiplicity MUST be one!  As far as I can tell, constraints on the number of Tuples for a given associated Class can only be handled by Class level constraints on the AssociationClass.  For example, "a Player can only be a goalie on no more than two team in a season".
[size=0]©2005 Paolo Cantoni, -Semantica-[/size]
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Lozenge (tm) & OCL
« Reply #11 on: March 05, 2006, 07:48:10 pm »
I received an off-line question which might be of interest to EAers.  Here's the question and the (slightly) amended response...

Quote
Would you use an association class or a ternary association to model a legal contract between two parties?
Personally, I like the association class approach best; the contract defines the relationship between the two parties.

Unfortunately it's at least a ternary:

A contract between First Party and Second Party under a Jurisdiction.  If one (incorrectly) assumes that all contracts will be written under the same jurisdiction then one can use the binary relation (and thus the AssociationClass).

However, you can try to get the best of both worlds by using the AssociationClass to model the Parties and use a single (additional) AssociationEnd (an EA Association - stereotyped «end») to add the Jurisdiction link.

This is the beauty of the AssociationClass is just a binary Lozenge approach!  8)  

However, since EA doesn't really provide access to all the Ends in the same way under this approach, I prefer a ternary Lozenge.

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!