Author Topic: UML class - modelling two classes with dependent/derived attribute enumerations  (Read 6396 times)

mattie

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Hi all
I'm trying to model out a class diagram and I'm struggling with how best to approach a particular aspect.

It's probably best to give the business explanation - I have two availability statuses, one primary and one secondary, and the secondary is effectively a further enumeration of the first - e.g. a primary might be 'busy' and the secondary 'in a meeting' or 'attending a training course' - the secondary is therefore limited by the primary. 

The primary is used to see if work can be assigned, the secondary to understand how long until the status will expire, so they both need to be modelled out.  I can easily set the primary to refer to one enumeration, the secondary to a separate enumeration, but I'm not sure how to represent that the secondary enumerations are partitioned by primary (e.g. 'In a meeting' is valid for primary state of busy, but not for primary state of 'on break' which might have enumerations of 'comfort break', 'meal break' etc.)

Would I better just having one class of availability, with attributes of Primary and Secondary each with separate associations to the requisite enumeration classes, or is there a means of modelling out this dependency having these statuses as separate classes?

I'm probably missing an easy trick here, but I'm going round in circles on this one.

Many thanks!

qwerty

  • EA Guru
  • *****
  • Posts: 11319
  • Karma: +287/-259
  • I'm no guru at all
    • View Profile
I'd probably model that as <<enumeration>> of <<enumeration>>.

q.

mattie

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Would that mean that each enumerated literal of the primary would reference out to its own enumeration of permissible secondary literals? 

Could do so, although think we might run into issues if the set of primary enumerations was in any way volatile (I have of course been assured these wont change, but that usually means they'll change!)

I'll mull it through - cheers for comment, much appreciated.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 10313
  • Karma: +334/-30
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
What you can do, and is also doable to implement in a database is the following:

- Enumeration: MainStatus
- Enumeration: SubStatus

In the SubStatus enumeration add an attribute of type MainStatus
For each value of the substatus you can now add the main status it belongs to.

Downside to this approach is that it is hard to express that relation at design time as the attribute values are set at runtime.

Geert

mattie

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Thanks for comments.  I've had a quick go at adding attributes to an enumeration - do you know how to perform this in Sparx 15?  I have previously just added literals as attributes of an enumeration to giver a simple list, and I'm not sure where to add attributes to these attributes, if you see what I mean!

(As an aside, I updated from sparx V12 to 15 and the way enumerations seem to work has changed - previously I'd go to the details tab and there would be a button for attributes (as per classes) but this details tab has disappeared for enumerations - I cannot seem to find how to add literals/attributes, and I'm reduced to copying existing enumerations and changing the attributes by double-clicking each attribute in turn.  I suspect I've changed a setting somewhere, but I'm at a loss as to what it is!)

Cheers to both for inputs, much appreciated.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 10313
  • Karma: +334/-30
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
F9 usually gets you the attributes view.
In v15 you can also right click and choose Features | Attributes

The difference between a literal value, and an attribute is in the property Is Literal.

When editing the features of an enumeration, EA will set that to true by default.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 11319
  • Karma: +287/-259
  • I'm no guru at all
    • View Profile
Would that mean that each enumerated literal of the primary would reference out to its own enumeration of permissible secondary literals? 
Exactly. You can assign any type to an attribute of an enumeration. So you can also use an enumeration for that. Even a recursive definition is possible (though I can't thin of an application for that).

q.

mattie

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Many thanks, I've included the two enumerations and have a single class with two attributes using the representative enumerations, and the secondary enumeration has an attribute referencing the primary.  This also allows me to add a duration attribute to the secondary state, which won't be associated to the primary.