Book a Demo

Author Topic: Navigability  (Read 19623 times)

thomaskilian

  • Guest
Re: Navigability
« Reply #15 on: February 15, 2006, 05:26:01 am »
Paolo,
I was afraid you would point me to this thread (your link above is incorrect). I don't see any n-ary association with n>2 there. So I'm still unillumined.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Navigability
« Reply #16 on: February 15, 2006, 06:12:29 am »
Quote
Paolo,
I was afraid you would point me to this thread (your link above is incorrect). I don't see any n-ary association with n>2 there. So I'm still unillumined.
Thomas,

(fixed the link - Thanx)

here's an amended ternary (3-Ary) AssociationClass example...

Below is the required code for C# to create and manage this relationship.  (BIG NOTE: I don't have a C# compiler to hand to verify this amended code will work...)

First the Class definitions...   [Note for simplicity's sake, I've made all the attributes public.]

public class BreadProduct
{
   public ArrayList _DoughFormulations = new ArrayList();    //because the Association is optional manifold
   public int Value;    //Just to show we got here...
   public BreadProduct()
   {
   }

   public void AddDoughFormulation(DoughFormulation associatedDoughFormulation)
   {
       _DoughFormulations.Add(associatedDoughFormulation);
   }
}

public class BreadDough
{
   public ArrayList _DoughFormulations = new ArrayList();    //because the Association is optional manifold
   public int Value;    //Just to show we got here...

   public BreadDough()
   {
   }

   public void AddDoughFormulation(DoughFormulation associatedDoughFormulation)
   {
       _DoughFormulations.Add(associatedDoughFormulation);
   }
}

public class BreadBaker
{
   public ArrayList _DoughFormulations = new ArrayList();    //because the Association is optional manifold
   public int Value;    //Just to show we got here...

   public BreadBaker()
   {
   }

   public void AddDoughFormulation(DoughFormulation associatedDoughFormulation)
   {
       _DoughFormulations.Add(associatedDoughFormulation);
   }
}


public class DoughFormulation
{
   public BreadDough _BreadDough;
//AssociationEnd
   public BreadProduct _BreadProduct;
//AssociationEnd
   public BreadBaker _BreadBaker;
//AssociationEnd

   private DoughFormulation()
//Remove parameterless constructor from public view...
   {
   }

   public DoughFormulation(BreadProduct BreadProduct, BreadDough BreadDough, BreadBaker BreadBaker, int BreadType, int Yield)
   {
       _BreadProduct = BreadProduct;    //set reference to AssociationEnd
       _BreadDough = BreadDough;    //set reference to AssociationEnd
       _BreadBaker = BreadBaker;    //set reference to AssociationEnd

       _BreadType = BreadType;        //set AssociationClass Attribute
       _Yield = Yield;        //set AssociationClass Attribute

       _BreadProduct.AddDoughFormulation(this);    //Inject reference to AssociationClass
       _BreadDough.AddDoughFormulation(this);    //Inject reference to AssociationClass
       _BreadBaker.AddDoughFormulation(this);    //Inject reference to AssociationClass
   }
   public int _BreadType;
   public int _Yield;
}



Next, the code to test and verify the structures...

   BreadProduct oBreadProduct = new BreadProduct();
   oBreadProduct.Value = 23;
   BreadDough oBreadDough = new BreadDough();
   oBreadDough.Value = 77;
   BreadBaker oBreadBaker = new BreadBaker();
   oBreadDough.Value = 92;

   DoughFormulation oDoughFormulation = new DoughFormulation(oBreadProduct, oBreadDough, oBreadBaker, 1, 5);
   oDoughFormulation = new DoughFormulation(oBreadProduct, oBreadDough, oBreadBaker, 2, 7);

   System.Collections.IEnumerator oIterator = oBreadProduct._DoughFormulations.GetEnumerator();
   while ( oIterator.MoveNext() )
   {
       DoughFormulation oIteratedDoughFormulation = (DoughFormulation)oIterator.Current;
       Trace.WriteLine(oIteratedDoughFormulation._BreadType + "->" +  oIteratedDoughFormulation._BreadDough.Value + ", " +  oIteratedDoughFormulation._BreadBaker.Value);
   }

   oIterator = oBreadDough._DoughFormulations.GetEnumerator();
   while ( oIterator.MoveNext() )
   {
       DoughFormulation oIteratedDoughFormulation = (DoughFormulation)oIterator.Current;
       Trace.WriteLine(oIteratedDoughFormulation._BreadType + "->" +  oIteratedDoughFormulation._BreadProduct.Value + ", " +  oIteratedDoughFormulation._BreadBaker.Value);
   }

   oIterator = oBreadBaker._DoughFormulations.GetEnumerator();
   while ( oIterator.MoveNext() )
   {
       DoughFormulation oIteratedDoughFormulation = (DoughFormulation)oIterator.Current;
       Trace.WriteLine(oIteratedDoughFormulation._BreadType + "->" +  oIteratedDoughFormulation._BreadProduct.Value + ", " +  oIteratedDoughFormulation._BreadDough.Value);
   }


See how we use the DoughFormulation to traverse to the BreadDough and BreadBaker, BreadBaker and BreadProduct, BreadDough and BreadProduct

Lastly, the output...

1->77,92
//Bread type 1 was baked by Baker 92 using Dough 77
2->77,92
//Bread type 2 was baked by Baker 92 using Dough 77
1->23,92
//Bread type 1 was baked by Baker 92 yielding Product 23
2->23,92
//Bread type 2 was baked by Baker 92 yielding Product 23
1->23,77
//Bread type 1 was baked using Dough 77 yielding Product 23
2->23,77
//Bread type 2 was baked using Dough 77 yielding Product 23


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

thomaskilian

  • Guest
Re: Navigability
« Reply #17 on: February 15, 2006, 12:15:04 pm »
Nice way to create n-tuples. Funny that I still have the feeling you don't really need such constructs. A practical use (that comes to my mind) is a sort of statistics where you want to bind results to the bread/baker/dough-tuples (e.g. subjective taste). Stand-alone above n-tuples have no semantic, do they? I'd prefer to use a matrix instead. Maybe I'm too old-fashioned/stupid?

nifsmith

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Navigability
« Reply #18 on: February 15, 2006, 01:21:15 pm »
Thanks for all the reply's.

I think I am closer to understanding this aspect of navigabilty. I will work through the C# example.

Paolo do I understand your analogy of the link table correctly.

Table X

col1 col2 col3
FKA  FKB  FKC  {unique combination = PK}
FKA  FKB  FKC  {unique combination = PK}
.....   ...     etc

Where FKA FKB & FKC hold some FK value of table A, B & C

SELECT DISTINCT A FROM X, A being some FK value of Table A.

The navigability statement I originally posted indicated that this was only possible if you had all the values except  one.

"Navigability means that given values for all but one of the association ends, the tuples containing all those values can be obtained; the result is usually stated as the set of values for the remaining association end."

Resulting in the select statement becoming

SELECT DISTINCT A FROM X WHERE B = ? AND C = ?

The select is based on knowing a value for two of the foreign key values, tying up with the statement.

Is this what you meant?

nif




People should not be afraid of their Governments. Governments should be afraid of their people.

V

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Navigability
« Reply #19 on: February 15, 2006, 01:49:31 pm »
Quote
Nice way to create n-tuples. Funny that I still have the feeling you don't really need such constructs. A practical use (that comes to my mind) is a sort of statistics where you want to bind results to the bread/baker/dough-tuples (e.g. subjective taste). Stand-alone above n-tuples have no semantic, do they? I'd prefer to use a matrix instead. Maybe I'm too old-fashioned/stupid?

Thomas,

they have the same semantics as an N-Ary intersector table in the relation model (or your matrix).  The links mean what you define them to mean.  In the case of a binary Association because, by definition, if B = f(A), then A = f-1(B) (that is, the inverse access function can be used to determine the the the other end) you appear to have more control over the semantics.  Example, if you are my child, then I'm your parent.  With an N-ary relationship, I haven't found a useful way to name the actual AssociationEnd (as opposed to the Role identified by that AssociationEnd).

The matrix (versus lattice) is just an implementation decision.

Paolo
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: Navigability
« Reply #20 on: February 15, 2006, 02:00:20 pm »
Quote
Thanks for all the replies.

I think I am closer to understanding this aspect of navigability. I will work through the C# example.

Paolo do I understand your analogy of the link table correctly.

Table X

col1 col2 col3
FKA  FKB  FKC  {unique combination = PK}
FKA  FKB  FKC  {unique combination = PK}
.....   ...     etc

Where FKA FKB & FKC hold some FK value of table A, B & C
Nif,  

I should have made it clearer that if you have more than one domain column in the PK, then the equivalent N-Ary PK is created by adding the extra columns to the PK.  For example if I am using a time period then the PK might be:
FKA  FKB  FKC  commencement termination {unique combination = PK}

and thus the same combination of FKA, FKB and FKC could appear more than once.

Sorry for being inexact.  
Quote
SELECT DISTINCT A FROM X, A being some FK value of Table A.

The navigability statement I originally posted indicated that this was only possible if you had all the values except  one.

"Navigability means that given values for all but one of the association ends, the tuples containing all those values can be obtained; the result is usually stated as the set of values for the remaining association end."

Resulting in the select statement becoming

SELECT DISTINCT A FROM X WHERE B = ? AND C = ?

The select is based on knowing a value for two of the foreign key values, tying up with the statement.

Is this what you meant?

nif

Yes, but recognising that in the limit case, you have
SELECT DISTINCT A FROM X
whose semantics are:
Give me the As that have ANY relationship to either Bs or Cs.

Hopefully closure...  8)

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

SF_lt

  • EA User
  • **
  • Posts: 216
  • Karma: +1/-0
  • The Truth Is Out There
    • View Profile
Re: Navigability
« Reply #21 on: February 21, 2006, 05:17:31 am »
Paolo, could you also provide class diagram (using lozenge) for this example and textual representation of it (how to read diagram)...
And, if not hard, example's diagram using associations (not lozenge notation) - hope that's for all cases :P

Isn't DoughFormulation the lozenge in your example?

Quote
here's an amended ternary (3-Ary) AssociationClass example...


when N=2, there is an association class case, so n-association when n=2 is an association class

when N>2, isn't lozenge a class? if so, it can have methods/attributes and so on
« Last Edit: February 21, 2006, 05:34:53 am by SF_lt »
registertm everything to SparX

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Navigability
« Reply #22 on: February 23, 2006, 06:50:27 am »
Quote
Paolo, could you also provide class diagram (using lozenge) for this example and textual representation of it (how to read diagram)...
And, if not hard, example's diagram using associations (not lozenge notation) - hope that's for all cases :P

Isn't DoughFormulation the lozenge in your example?


when N=2, there is an association class case, so n-association when n=2 is an association class

when N>2, isn't lozenge a class? if so, it can have methods/attributes and so on
Diagrams will have to wait a bit.  Very busy at present.

However... Yes, DoughFormulation is the AssociationClass/Lozenge.

Therefore it can have its own attributes and methods.  But as an AssociationClass, it also has special attributes that act as the AssociationEnds.  I distinguish those with the «end» stereotype.

HTH,
Paolo
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: Navigability
« Reply #23 on: February 23, 2006, 02:46:35 pm »
I just remembered I have his model that might help...  Let me know if you need more...



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

nifsmith

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Navigability
« Reply #24 on: February 24, 2006, 02:06:56 pm »
Thanks for the diagram Paolo, helps a lot.

I am confused however (there's a suprise) the UML Reference Manual 2nd edition states that "Aggregation (including composition) is only meaningful for binary associations. An n-ary association may not contain an aggregation or composition marker on any role." It doesn't state why.

I ran an n-ary and aggregation search in the draft version of the UML2 superstructure document that I have and this also states that "only binary associations can be aggregations."

If EA allows you to model aggregations or compositions on an n-ary associations then it would appear that this conflicts with the UML superstructure document.  I have tried it and EA allows you to place an composite/aggregation marker on either end of the association.

Any thoughts on this.

nif
People should not be afraid of their Governments. Governments should be afraid of their people.

V

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Navigability
« Reply #25 on: February 24, 2006, 05:40:00 pm »
Quote
Thanks for the diagram Paolo, helps a lot.
Hi nif,
Before I (attempt to) answer your questions a few words about the diagram (and EA).  Firstly, this is MY modelling methodology - so, apologies if I have confused anyone.  The AssociationEnds and their adornments are created using the facilities that EA has to support these concepts (which like almost all UML tools are close to zero).

The connectors between the lozenge and the associated classes are AssociationEnds - not full (binary) Associations. That is, they are the half-line from where the AssociationClass dotted connector meet the Association back to the Class.  Thus the Association from Class T to Class U contains 2 AssociationEnds.

I needed to distinguish these AssociationEnd lines from the normal ones, I colour them deep purple (Great Band!) and by attaching the Composition marker makes it look weird enough.

I guess that I should also mention that while an AssociationClass is a real Class, an ordinary class can't do the same job.  An AssociationClass is an ordinary Class plus an Attribute for each AssociationEnd.  These attributes need to be distinguished from the other attributes (as the «end» stereotype does for the AssociationEnd).  Strangely enough,I use the «end» stereotype for this purpose.

Quote
I am confused however (there's a surprise) the UML Reference Manual 2nd edition states that "Aggregation (including composition) is only meaningful for binary associations. An n-ary association may not contain an aggregation or composition marker on any role." It doesn't state why.

I ran an n-ary and aggregation search in the draft version of the UML2 superstructure document that I have and this also states that "only binary associations can be aggregations."
Since the (normal) Aggregation describes the meronymic relationship between the holonym (say Class T) and the meronyms (say Class U).  This requires a differentiation between the two classes (one the holonym, one the meronym).  In an N-ary Association this isn't possible.  All the classes have the same (notional) weight.  (Try to "speak" any N-ary Association to give one associated Class more weight than another)

The AssociationClass (if any) on the Association doesn't have any bearing on the Aggregation/Composition.

Quote
If EA allows you to model aggregations or compositions on an n-ary associations then it would appear that this conflicts with the UML superstructure document.  I have tried it and EA allows you to place an composite/aggregation marker on either end of the association.

Any thoughts on this.

nif
As I mentioned above, support for N-Ary associations is lacking in (all?) UML tools.  EA does NOT see the connector between the Lozenge and the associated Class as an AssociationEnd.  Thus it allows the Composition marker at either end.

Admittedly, placing the Composition maker at the associated Class end is MY methodology, but I feel it IS consistent with both UML and Set theory.  My preference would be for a different line style for Association Ends.

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