Book a Demo

Author Topic: Aggregation's Code Generation  (Read 4460 times)

wmac

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Aggregation's Code Generation
« on: February 22, 2004, 12:36:54 pm »
This is about the aggregation notation's code generation.

I want to have below structure:


{Company Class} <>-1------1.n- {Employee Class}

Actually I want an ArrayList in company class which will hold a list of employees.

C# code generation (and also Delphi and PHP) produces a code like below for Company Class:

-------------------
public class Company {
  public Employee;
  public Company(){
    }

  ~Company(){
   }

 public virtual void Dispose(){
   }

 protected virtual void Finalize(){
  }
}//end Company
-------------------

As you see code generation adds a single Employee object in "Company" class instead of a ArrayList or something like that.

What's wrong? Is there any problem with my diagram or what? How can I achive what I need?

Again Thank you for your time.

Regards,
Mac

cdelarge

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Aggregation's Code Generation
« Reply #1 on: February 23, 2004, 10:04:28 am »
If you click on Tools > Options you can setup what aggregations translate to in your code.

For example, I use C# so under Tools > Options highlight C# (under the Generation + sign).  Then click on the "Collection Classes" button.  Inside there you can setup your defaults for "Default Collection Class", "Collection Class for Ordered Multiplicity", "Collection for Qualified Multiplicity".

I used ArrayList, SortedList, and Hashtable respectively.

Re-run your code generation and you should have your arraylist variable setup automatically.  Don't forget to fix your multiplicity under the link properties.

CD

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Aggregation's Code Generation
« Reply #2 on: February 23, 2004, 03:03:35 pm »
CD,

I'd really appreciate it if you could expand on this a bit.  I have followed your instructions but still get a single field generated.

Using Mac's simple model:

Class Company
has field EmployeeList which is a collection (unordered) of ActiveEmployee objects of class Employee.

I have followed thi process:
1) create class "Employee" with two attributes (ID and Name) set as properties.
2) create class "Company"
3) add attribute "ActiveEmployees" to Company, setting type to "Employee"  and creating property
4) set mulitplicity of attribute "ActiveEmployees" to 1..*
5) set Attribute Is a Collection checkbox
6)add Aggregation link from Employee to Company, setting source role to ActiveEmployees, source mulitplicity to 1..*, target multiplicity to 1

I still get:
=================================
public class Company {
     private Employee ActiveEmployees;
     public Company(){
     }
     ~Company(){
     }
     public virtual void Dispose(){
     }
     protected virtual void Finalize(){
     }
     public Employee ActiveEmployee {
           get{
                 return ActiveEmployee;
           }
           set{
                 ActiveEmployee = value;
                             }
     }
}//end Company
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

wmac

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: Aggregation's Code Generation
« Reply #3 on: February 23, 2004, 11:52:59 pm »
cdelarge

Thank you very much. Yes it worked properly now. It's strange that I had not seen those options there.

Regards,
Mac
---
sargasso

Just create a simple diagram like this
{Company Class} <>-1------1.n- {Employee Class}

and it should work. Then work arround it to reach your own design.

Ma

angel-o-sphere

  • EA User
  • **
  • Posts: 112
  • Karma: +0/-0
    • View Profile
Re: Aggregation's Code Generation
« Reply #4 on: March 08, 2004, 07:48:52 am »
I have a similar question:

I configured the usage of collection classes, however the generated attributes are not initialized.

I'm working with Java and I get stuff like this:

java.util.ArrayList employeeList;
instead of:
java.util.ArrayList employeeList = new java.util.ArrayList();
Regards,
  angel'o'sphere
« Last Edit: March 08, 2004, 07:49:08 am by aos »