Book a Demo

Author Topic: UML class attribute behavior  (Read 3264 times)

AlanT

  • EA User
  • **
  • Posts: 66
  • Karma: +0/-0
    • View Profile
UML class attribute behavior
« on: November 29, 2010, 08:10:46 am »
   This is probably a silly question, to which I should know the answer, but . . . I need to model the behavior of certain attributes of a UML class that are important for processing.  I want to do this with a state machine.  

  Question:  To do this (in a way that makes sense), do I need to make each attribute a class, so I can associate a state machine diagram with it?

              Thanks, Alan
 :-[     :-/  


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: UML class attribute behavior
« Reply #1 on: November 29, 2010, 05:10:05 pm »
Alan,

Attributes are structural features, and therefore, by definition don't have behavior. (otherwise it would be behavioral features)
Why don't you tell us the exact context, it might lead to better answers.

Geert

AlanT

  • EA User
  • **
  • Posts: 66
  • Karma: +0/-0
    • View Profile
Re: UML class attribute behavior
« Reply #2 on: November 30, 2010, 01:35:25 pm »
   Classes are also structural, but you can describe their behavior with, for example, a state machine.  In this way, behavior can be linked to structure.  

    Here is an example: I have data associated with a car`s position.  Two attributes of the car's position in my data model are: Eligible and Reported, both boolean.  Eligible means whether or not the car's position meets certain criteria (a logical algorithm) to be reported to external systems.  Reported means whether or not the position has actually been reported to external systems.  

     I want to model the behavior of these attributes, i.e., the logical algorithms associated with them.  Perhaps I should simply treat Eligible and Reported as substates of the state machine for the class (car position).

                          Thanks, Alan

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: UML class attribute behavior
« Reply #3 on: November 30, 2010, 05:17:42 pm »
Alan,

Classes contain indeed both behavior and structure, but with attributes that's different.

In fact what you describe is indeed the states of the Car class or if you want the CarPosition class.
The attributes contain the state, but it is still the state of the owning class.
What we do to model the state behavior of a class is:
- Define an enumeration with all the states (of a certain level) of the class
- Create attribute with stereotype "state" on the class and set its type to the enumeration
- Create a state machine with the same name as the state attribute (so you can distinguish them in case you have multiple states)
- Create a diagram under the state machine and put the states on that diagram.

Geert
« Last Edit: November 30, 2010, 05:17:57 pm by Geert.Bellekens »