Book a Demo

Author Topic: Object Diagram - Create objects from classes  (Read 13888 times)

madammox

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Object Diagram - Create objects from classes
« on: October 09, 2008, 10:25:42 pm »
Hi,

I've modeled a bunch of classes in a class diagram, each class with a number of attributes. Now I want to create various object diagrams to model snapshots of the class instantiations and attribute values.

I can create objects from the object diagram toolbox and set the object's instance classifier to the corresponding class.

Now I can see the attributes of my object(s), but how can I apply object(say instance)-specific values to them? Whenever I access the attributes, it's always the attribute definition of the class, not the object.

Probably my approach is bad. What am I doing wrong?

Regards,
Max

Lars H

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Object Diagram - Create objects from classes
« Reply #1 on: October 09, 2008, 11:42:03 pm »
I don't think you can set attribute values on objects in EA. You can set values on attributes in a class, but that will then become the initial value as generated in code: "class X { int y = 300; }"

You cannot design in EA something that corresponds to "X x1; x1.y = 150;"
« Last Edit: October 09, 2008, 11:43:40 pm by lars.h »

madammox

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Object Diagram - Create objects from classes
« Reply #2 on: October 10, 2008, 12:23:16 am »
You can work around this by defining each object uniquely. EA allows you to define attributes for objects the same way as for classes, including the "default" value (That's what I'm actually doing).

However, as the instantiated objects do not know about their class then, there is no way to for example extend a class later with additional attributes which are in term reflected by the objects  :-[

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Object Diagram - Create objects from classes
« Reply #3 on: October 10, 2008, 08:57:32 am »
Quote
I can create objects from the object diagram toolbox and set the object's instance classifier to the corresponding class.

Now I can see the attributes of my object(s), but how can I apply object(say instance)-specific values to them?
Right-click > Advanced > Set Run State (Ctrl+Shift+R)
The Sparx Team
[email protected]

madammox

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Object Diagram - Create objects from classes
« Reply #4 on: October 10, 2008, 06:13:55 pm »
Thanks, that's it!

Lars H

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Object Diagram - Create objects from classes
« Reply #5 on: October 10, 2008, 06:43:58 pm »
I learned something new. Thanks a lot!