Book a Demo

Author Topic: Constructor method definition  (Read 5623 times)

twetmore

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Constructor method definition
« on: August 24, 2004, 02:42:22 pm »
Greetings,

I have just started using EA (4.10, build 734) and I'm sure this is one of the dumbest questions ever, but I've searched all over the User's Guide and this forum with no success...   :)

How can I designate a class method/operation as a constructor in EA?  Or does it treat constructors as normal operations?

It seems to me that it would need to be able to tell the difference, so that if I derive a class, EA can automatically override the constructors correctly (and give them the derived class' name).

Thanks!

Tony

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Constructor method definition
« Reply #1 on: August 24, 2004, 07:52:33 pm »
Tony,

Im not sure here (Im a .net only type of person) but ...

EA will generate code for a class constructor depending on the code generation settings not on some setting of a method. However, I am not sure that I'd ever want to automatically override the parent class constructor in the child class?

Thus class FruitShop descending from Shop will be generated with a constructor "public FruitShop() {} and Shop will be generated with "public Shop() {}" and I dont need to do anything in EA.  I cant really see a use for having a method "public Shop() {} in the FruitShop class (but I suppose someone will have a use for it).
Exposing a parent constructor??????

OTOH!!! One painfull thing is that EA cannot adequately (my opionion) model and highlight overloaded constructors - especially constructors with "nom-de-plumes" as I found out trying to polymorph things in C#.
Oh well

Bruce
"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.

twetmore

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Constructor method definition
« Reply #2 on: August 25, 2004, 07:21:52 am »
Bruce,

Yes, I did see mention of EA's ability to generate code for a (presumably "default") constructor in the user's guide.

I've never used C#, but in C++ and Java, it is quite common to define multiple (overloaded) constructors, each taking a different set of parameters.  I would like to be able to model these constructors in EA.  Perhaps this is what you meant in your final paragraph.

In terms of overriding constructors in derived classes, to follow your example with some pseudocode:

 class Shop
 {
   Shop( string shopName )
 }

 class FruitShop derives from Shop
 {
   FruitShop( string shopName )
 }

I would like to be able to model the FruitShop derived class in EA and tell it to override the "Shop(string)" constructor automatically, just like I can override any other methods.  Of course, in doing so, EA would name the overridden constructor FruitShop(), not Shop().  Obviously (at least in C++ and Java), you cannot define a base class constructor in a derived class.

If I derive a class in EA now, I see a list of methods that I can selectively override.  I would like to be able to override constructors in this same way.  EA wouldn't automatically override them, of course, it would just give me the opportunity to do so.

Hope this helps to make things more clear.

Thanks.

Tony

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Constructor method definition
« Reply #3 on: August 25, 2004, 04:40:32 pm »
Yep, we are on the same wavelength here - just expressed slightly differently.

I agree with what you are asking for - a way to denote that a class has several methods which are overloaded  constructors.  In general a specialization class would need to "override" each of the constructors in that it needs to provide its own constructors matching the set of parent constructors.

That was the good news, this is the bad....
No, EA doesn't do what we want.  The only way I have been able to control the design so that the proper constructors are provided is to denote each constructor as a stereotyped method (<<ctor>>), when creating the specialisation I then ovveride the constructors and manually change the names.

Such is life

Bruce


p.s.  The UML 2.0 doesn't seem to suport what we want either!
« Last Edit: August 25, 2004, 05:45:48 pm by sargasso »
"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.

twetmore

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Constructor method definition
« Reply #4 on: August 27, 2004, 08:02:46 am »
Bruce,

That is somewhat disappointing, but not the end of the world, of course.  I'll work around it some how, as you have.

Thanks for your help and insight.

Tony