Book a Demo

Author Topic: Newbie Question - Object Diagram  (Read 5716 times)

edusem

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Newbie Question - Object Diagram
« on: April 24, 2008, 10:23:32 am »
I created a class diagram that has 2 classes (call them ClassA and ClassB respectively).  ClassA depends on ClassB and it's represented by a dependency association in the diagram.

I tried to create an object diagram with 2 instances of ClassB and an instance of ClassA and this is what I found:

* If I give an initial value to one of the attributes of one of ClassB objects, all objects of ClassB have the same attribute value.  Is this the expected behavior?

* To counter this, I set the values in the run state of the object and it allowed me to keep e/a of the ClassB objects with different attribute initial values.  Is this the correct approach?

* I manually set the attributes for the ClassA object with the same initial values of the ClassB objects.  Is there a way to force the dependency and get the "depended of" values automatically?

What are "best practices" to create an object diagram from class diagrams in EA?
I'm fairly new at this and still learning.  Thanks,


Ed.

Torsten Binias

  • EA User
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Re: Newbie Question - Object Diagram
« Reply #1 on: April 24, 2008, 06:30:33 pm »
Hi Ed,

Quote
If I give an initial value to one of the attributes of one of ClassB objects, all objects of ClassB have the same attribute value.  Is this the expected behavior?
Setting the inital value for an attribute a in the properties dialog of the class realls means that this value is initially assigned to a in all objects of that class.

Quote
If I give an initial value to one of the attributes of one of ClassB objects, all objects of ClassB have the same attribute value.  Is this the expected behavior?
Yes!. Setting the values in the run state is the correct approach.

Quote
I manually set the attributes for the ClassA object with the same initial values of the ClassB objects.  Is there a way to force the dependency and get the "depended of" values automatically?
I cannot think of any depency that would allow for such a thing. What do you mean with "dependend values"?

If ClassA has an attribute a that can be calculated by values of ClassB you should mark a as being derived and specify (e.g. with OCL) how to calculate the value.

An example:
class A {
int a;
B theB;
}

class B {
int b, c;
}


Let's say A.a can be computed as the sum of the attribute values of B. Then you do the following:

1. Mark A.a a as being derived (a slash will appear in front of the attribute in your class diagram).

2. In the Note of A.a you write:
"{OCL} let a = theB.b + theB.c"

HTH,
Torsten

peter.zrnko

  • EA User
  • **
  • Posts: 253
  • Karma: +0/-0
    • View Profile
Re: Newbie Question - Object Diagram
« Reply #2 on: April 24, 2008, 11:30:31 pm »
There is only one way how to set Run state of an Object - Ctrl+Shift+R (Set Run State).

But there are two ways how to show this run state
- do nothing
   - you will see only values set by "Set Run State"
   - initial values will be not visible
- Feature Visibility / Inherited Features - Show Attributes
   - you'll see all "inherited" attributes with their default values
   - values set by "Set Run State" will be displayed instead of initial values where applicable
   - this way could be used together with "Hide Object Run State in Current Diagram"
« Last Edit: April 24, 2008, 11:33:03 pm by peter.zrnko »
Peter