Book a Demo

Author Topic: Extending an enumeration  (Read 15223 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Extending an enumeration
« on: October 01, 2009, 11:55:50 pm »
Hi,

I'm breaking my head here on the subject of extending enumerations.
According to UML specs and the (not very helpfull) EA help it should be possible to extend an enumeration, but nowhere is stated how this should be done.

I've been thinking about inheritance, but that seems to work a bit akward. Suppose following situation:
EnumA with literal A1
EnumB with literal B1

If EnumB generalizes enumA, what exactly does that mean?
You could argue that, since for every instance of EnumA we could use an instance of EnumB that an attribute of type EnumA now can hold both A1 as B1 literals.

So now what happens with an attribute of type EnumB. You could argue, that since EnumB inherits everything from EnumA we should be able to set the value of the attribute to A1 as well as B1. (so now it doesn't matter wether your the type of the attribute is EnumA or EnumB)

... I'm confused ...   :'(

Geert

Dave.B

  • EA User
  • **
  • Posts: 94
  • Karma: +0/-0
    • View Profile
Re: Extending an enumeration
« Reply #1 on: October 02, 2009, 12:23:26 am »
Geert,
I think your forgetting something: The OO generalise is not the same thing as C++ inheritance. The opposite of generalise is specialise or sub-class of. Therefore if EnumB is a subclass of EnumA then it can only have at most the values of EnumA in it. If you want to extend the set of values in EnumB with those from EnumA and someother Enum set then you would have to create a union of the two.

From a code gen point of view, the simplest way to use an <<extends>> connector and let EnumB extend EnumA.

Dave B.

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: Extending an enumeration
« Reply #2 on: October 02, 2009, 12:30:54 am »
Hi Geert,

I can't really tell how UML intends to do it. In programming language it is usually not done by inheritance (which isn't supported by all programming languages anyway),
but making definitions in the generalizing enum refering to the values from the generalized enum.
S.th. like this:

enum A
{
   literalA1 ,
   literalA2
};

enum B
{
  literalB1 = literalA1 ,
  literalB2 = literalA2 ,
  literalB3
};

HTH,
Günther

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Extending an enumeration
« Reply #3 on: October 02, 2009, 12:39:42 am »
Hi Geert,

Both Dave and Gunther make important points.  From a conceptual modelling point view, I think enumeration subsets are combined into supersets by means of shared aggregations - in an acyclic directed graph.

I'd have to go and check some models of 4 years ago or so where I tried to model these at the conceptual level.

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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Extending an enumeration
« Reply #4 on: October 02, 2009, 05:01:03 pm »
Dave, you are right, I mixed up the words.
It should be EnumB specializes EnumA. Thanks for noticing.

I've been thinking about this issue a bit more, and indeed generalization doesn't seem like the right way to go to extend enumerations.
I've made the comparison between enumerations and other datatypes.
Lets take Integer and NaturalNumber. (not limited by any system or code restrictions).
We can say that a NaturalNumber is an Integer so that means that Integer is the generalization of NaturalNumber.
Anywhere where we use a value of type Integer we can use a value of type NaturalNumber, but not the other way around.
No the key I think is that NaturalNumber is a subset of Integer.
To me it seems that generalization is only usefull to define subsets for enumerations.
As example:
<<enumeration>>Weekday (monday through sunday)
<<enumeration>>WeekendDay(saterday and sunday)

In this example I think we can say that Weekday is the generalization of WeekendDay (WeekendDay is a subclass of WeekDay)

So although WeekendDay inherits from WeekDay that doesn't mean it also inherits all of its literal values.

Having established the meaning of the generalization between enumerations, I still have no clue on how to extend an enumeration (on the conceptual UML theoritical part. Sure I can make up my own convention, but I really want to know if there is some standard way)

Geert

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: Extending an enumeration
« Reply #5 on: October 06, 2009, 07:33:50 pm »
Hi Geert,

I think this cries out for <<extension>> / <<restriction>> 'generalization' relationships (in the sense they're used in XSD for example).
Not sure what the code generation would do about this. I'am also not in picture how these are modelled in the EA XSD profile, but that could be a starting point to investigate.

WBR
Günther