Book a Demo

Author Topic: More association questions - static instances  (Read 3751 times)

jkorman

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
More association questions - static instances
« on: March 12, 2004, 07:22:27 pm »
Java Code

class Bar { ... }

class Foo {
 public static Bar aBar = new Bar();
  ...
}

If I model the above with the static Bar instance, aBar, as an attribute, then I can properly mark
the attribute as static. However if I model using an association

  [Foo ]-------->[Bar]

I can name the assocation, make it aggregate/composition, set its multiplicy! But I haven't
found any way to indicate that "aBar" is static. Anyone have any ideas.

Thanks, Jim

whyteg

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • Mr Evaluator
    • View Profile
Re: More association questions - static instances
« Reply #1 on: March 15, 2004, 03:56:14 pm »
Jim,

On the source role tab of the association properties there is a field called "changeable" which has a drop down which allows: none, frozen or addOnly. I believe the frozen property is used to ensure that this role is static.

Hope this helps.

jkorman

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: More association questions - static instances
« Reply #2 on: March 15, 2004, 08:01:56 pm »
No, I don't think that "frozen" is it. When used it puts a frozen constraint on the "source" end of the
association.

I reverse engineered the following

// Classic Singleton pattern
public class Class1 {  private static Class1 theInstance = new Class1();

 private Class1() { // constructor }
}

I get the class diagram for Class1 with the following...

 a private association of Class1-->Class1 named theInstance
and
  a private static  attribute named theInstance with an initial value = new Class1().

Also, I went diving into the tables a little.
Attributes have a static entry, associations do not. Is this an oversight?

The UML seems to indicate that both can have a static feature.

Jim


benc

  • EA Administrator
  • EA User
  • *****
  • Posts: 200
  • Karma: +0/-0
    • View Profile
Re: More association questions - static instances
« Reply #3 on: March 24, 2004, 05:33:54 pm »
Hi Jim,

Under target role, you can set the target scope to classifier. During forward generation, this is checked and if set to classifier, a static attribute is created.

I will look into the reverse engineering case further.

Regards,
Ben