Book a Demo

Author Topic: composition and accessors  (Read 8028 times)

felix79

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
composition and accessors
« on: February 05, 2008, 01:21:37 am »
I design some aggregations and compositions in my class diagram and I would like the accessors (get and set) to be created automatically.
How can I do that ?

gpc

  • EA User
  • **
  • Posts: 111
  • Karma: +0/-0
    • View Profile
Re: composition and accessors
« Reply #1 on: February 05, 2008, 04:24:53 am »
Assuming you mean you've created a member item, say birthday and want the code to generate a getBirthday() and setBirthday() method?
I don't think EA will do that automatically for you, but I think you'll be able to create a script to handle this when you run the code generator.

Taz

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
  • Imagine, sun, beach and financial freedom
    • View Profile
Re: composition and accessors
« Reply #2 on: February 06, 2008, 03:44:50 am »
If you check the "Property" checkbox in the Attributes Dialog, it will automatically crate the get and set accessors.

gpc

  • EA User
  • **
  • Posts: 111
  • Karma: +0/-0
    • View Profile
Re: composition and accessors
« Reply #3 on: February 06, 2008, 07:34:02 am »
Cheers Taz, yep works great.

felix79

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: composition and accessors
« Reply #4 on: February 06, 2008, 07:44:20 am »
Taz : I don't understand what you're talking about...
I know your method works to generate get and set for an attribute, but I'm not creating an Attribute, but a composition or aggregation link. When you open the aggregation properties dialog, you can specify the name of the member that will be generated and its type, but there's nothing to generate the get and set method.

gpc

  • EA User
  • **
  • Posts: 111
  • Karma: +0/-0
    • View Profile
Re: composition and accessors
« Reply #5 on: February 06, 2008, 08:06:09 am »
Sorry Felix79, That was partly my fault.
Testing this a little bit, If you create the associations and then generate the code you will not create the attributes required. You'll need to reverse engineer from the generated code (i.e. sync) and then the attributes appear. From here you just select and check the property box and voila you have the get and set methods.

dirah

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: composition and accessors
« Reply #6 on: February 06, 2008, 08:23:36 am »
In which context is the property-checkbox available? I would like to create a set- or get-operation for a certain attribute of a class and the option is always greyed out (I mean not available). It doesn't matter if the attrbute is public, private, protected, static, read-only whatsoever..

What exactly is the property-checkbox therefor and when can I use it?
Is it availabe only for certain programming languages?
« Last Edit: February 06, 2008, 08:29:25 am by dirah »

gpc

  • EA User
  • **
  • Posts: 111
  • Karma: +0/-0
    • View Profile
Re: composition and accessors
« Reply #7 on: February 06, 2008, 08:29:03 am »
You need to enter an attribute and select it, then the box is un-grayed :)

dirah

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: composition and accessors
« Reply #8 on: February 06, 2008, 08:32:24 am »
ah ok, kinda strange.

You have to save the attribute (before that the option ist grey). after that you can select it in the list and the option is available. I had tried to set the option directly when creating the attribute.. :-)

gpc

  • EA User
  • **
  • Posts: 111
  • Karma: +0/-0
    • View Profile
Re: composition and accessors
« Reply #9 on: February 06, 2008, 08:36:56 am »
I guess it's sensible because it then pops up a dialogue which generates the methods based on the attribute, which wouldn't exist yet. But, yeah I found it a bit clunky too. :)

Martin Spamer

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: composition and accessors
« Reply #10 on: February 06, 2008, 09:08:40 am »
You should not be using getters in this way.  When you use a getter like this, getting the object then working on the object directly you are breaking the spirit of Encapsulation.

Instead, follow the Law of Demter Tell Don't Ask.

Tell the composition to do something, the composition should delegate (tell) to it's part.
« Last Edit: February 06, 2008, 09:10:45 am by Martin_Spamer »

gpc

  • EA User
  • **
  • Posts: 111
  • Karma: +0/-0
    • View Profile
Re: composition and accessors
« Reply #11 on: February 06, 2008, 09:25:19 am »
agreed, but sometimes it's just more cost effective to cut out the middle-man.