Book a Demo

Author Topic: Initialization for Association Relationship  (Read 4233 times)

Welcome

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Initialization for Association Relationship
« on: May 10, 2016, 08:21:23 pm »
Hi,

When I associate two class; A --> B (directed association),
class A has a member m_B (in the generated code).
My question is how to initialize the m_B to a proper instance.

Maybe some options would be
 1) using constructor: m_B = new B(); Anyway, how I could add constructor to A?  ;)
 2) using link relationship: for this, EA seems not to support this. In the object diagram, I cannot find link relationship.

The example is for Java.

Thanks many times.

Welcome

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Initialization for Association Relationship
« Reply #1 on: May 11, 2016, 09:14:58 am »
I got to know how to define constructor by defining operations in Operators page
 - set the operator's name as the same with class name with no return type (blank the return; not the void)
 - giving some parameters to it will define a new constructor.

But, how can I override the default constructor that EA generates?
If I add a constructor with no argument, then it has two default constructors; definitely error case.

Thanks.

Welcome

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Initialization for Association Relationship
« Reply #2 on: May 11, 2016, 09:52:06 am »
To initialize association relationship,
My temporary solution is

 1. draw association A to B
 2. add attributes to A. say it as m_B. set the type of m_B to B.
 3. In association property, set the role name to m_B. You can select with the drop-down menu.
 4. In attributes dialog, set the initial value for m_B as new B().

Welcome better ones.