Author Topic: XOR vs Cardinality order of precedence  (Read 1326 times)

jeshaw2

  • EA User
  • **
  • Posts: 701
  • Karma: +0/-0
  • I'm a Singleton, what pattern are you?
    • View Profile
XOR vs Cardinality order of precedence
« on: May 02, 2006, 08:43:11 am »
In my part of the world, a radio is considered to be an intrinsic (mandatory) component of my car.  When I buy the car I get to choose among three types of radios:  AM/FM, AM/FM/tape cassette, or AM/FM/tape cassette/CD player.  Only one of these will fit into the hole in the dashboard of the car.  The new car dealer needs to know which radio I want in my new car.

When I trade in my car for a new one, the new car dealer will sell off my old car to a wholesaler.  The wholesaler does not care which radio is in the car, but considers the car as being incomplete with some type of radio in it;  he does not want an empty slot in the dash board.

So now I'm wondering how to diagram the static structure of my car.  Certainly a radio is a component of the car and the car owns the radio within it; so I have a composite relationship between each of the three radios and the car.  To show that the radios are intrinsic to the car, I show a cardinality of 1:1 on each radio option.  To show the exclusivity I add the XOR constraint among the three options.

So if the three radio types are intrinsic to the car, but only one can get past the XOR constraint;  seems I have a conflict among the terms.  Which term (cardinality or XOR) takes precedence?  UML Superstructure is silent on this issue.
Verbal Use Cases aren't worth the paper they are written upon.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: XOR vs Cardinality order of precedence
« Reply #1 on: May 02, 2006, 08:56:23 am »
Hi Jim,

First, do you mean "without" here:
Quote
...as being incomplete with some type of radio in it...

Now to work.

I think we might want to come at this differently. Consider the radio as an attribute of the car. It has a cardinality of 1 (actually 0..1 but I'm trying to stay with the simplest case) and is of the abstract type 'radio.'

You have given a set of possible concrete subclasses of radio. This set is not necessarily closed or complete, so that other subclasses (or trees thereof) may be added later. However, they'll all fill the slot, only (a maximum) one can be present (due to the cardinality) and they will all annoy the wholesaler if missing...

Now we can get out of the business of a possibly complex constraint and just use a note for clarity. We can also describe the concepts of 'radio' and 'car' separately, each in their own context, and use structural models to define their relationship.

Best I can do off-hand (I'm in a coffee shop waiting for a meeting) but perhaps it will provide another perspective.

David
No, you can't have it!

jeshaw2

  • EA User
  • **
  • Posts: 701
  • Karma: +0/-0
  • I'm a Singleton, what pattern are you?
    • View Profile
Re: XOR vs Cardinality order of precedence
« Reply #2 on: May 02, 2006, 10:38:56 am »
Yes, I did mean without the radio.
I'm still thinking about yourapproach...
Verbal Use Cases aren't worth the paper they are written upon.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 6264
  • Karma: +104/-89
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: XOR vs Cardinality order of precedence
« Reply #3 on: May 02, 2006, 03:07:47 pm »
Jim,

I'd model the relationship between a generic car and generic radio.  I'd then specialize the radio into the three specific types.

That seems to model the two business rules you've enunciated:

A car MUST have a radio
A radio MUST be one of three types.

HTH,
Paolo
« Last Edit: May 02, 2006, 03:08:27 pm by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: XOR vs Cardinality order of precedence
« Reply #4 on: May 02, 2006, 03:12:21 pm »
With one exception I think Paolo and I are saying the same thing.

I've allowed for another case. A car MAY have ONE rado. This allows you to buy a car without a radio, but if you do get a radio there can only be one in the car, and it must be a valid specialization of the abstract radio class.

This also allows the wholesaler to receive a valid car, even though the radio slot is not filled.

Apart from that we're saying the same thing.

Strikes me this would all be easier to explain with a small UML model. Of course this was the whole idea of UML in the first place...
No, you can't have it!

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 6264
  • Karma: +104/-89
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: XOR vs Cardinality order of precedence
« Reply #5 on: May 02, 2006, 04:28:10 pm »
Quote
With one exception I think Paolo and I are saying the same thing.

I've allowed for another case. A car MAY have ONE radiio. This allows you to buy a car without a radio, but if you do get a radio there can only be one in the car, and it must be a valid specialization of the abstract radio class.

This also allows the wholesaler to receive a valid car, even though the radio slot is not filled.

Apart from that we're saying the same thing.

Strikes me this would all be easier to explain with a small UML model. Of course this was the whole idea of UML in the first place...
Yes, David.  I was just using Jim's rules as he'd specified them.

In my fact-based modelling methodology, you also need to account for:
"I know this car hasn't a radio"  
and:
"I know this car has a radio, but I don't know what kind it is."

This gets into the "Extrinsics" pattern.

Paolo
« Last Edit: May 02, 2006, 04:47:25 pm by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

jeshaw2

  • EA User
  • **
  • Posts: 701
  • Karma: +0/-0
  • I'm a Singleton, what pattern are you?
    • View Profile
Re: XOR vs Cardinality order of precedence
« Reply #6 on: May 02, 2006, 05:22:44 pm »
Where I live, it is next to impossible to buy a car without a standard radio in it; so 'no radio' was not an option in my case.

Thanks all, I got my answer about the car model.

I'm still not sure about the XOR vs cardinality precedence issue though;  or, are we saying that situation will never come up in a model?
Verbal Use Cases aren't worth the paper they are written upon.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: XOR vs Cardinality order of precedence
« Reply #7 on: May 02, 2006, 05:33:58 pm »
Jim,

XOR will certainly come up in a model. Thus the 'common' constraint and the various examples throughout the development of UML.

However, I don't think it is the best option for communication of intent in this case.

Regardless, the example of car and radio is a very good illustration of relationships in UML; easy to grasp and non technical.

FWIW, I wanted to stress the 'no radio' case since, regardless of whether it is possible (or reasonable) to obtain one of these car objects without a radio, it is doubtful that said object ceases to be a car if the radio is removed. Hopefully this extends rather than offends your metaphor.

David
No, you can't have it!