|
|
Re: [QVTo] Can a constructor call another constructor? [message #1849779 is a reply to message #1849776] |
Wed, 02 February 2022 13:23 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
lf you have a default constructor and an application constructor, you may expect an automated call of the default from the application. In a more complicated scenario you might want a cascade of constructors at least some of which would need to pass arguments.
Your default constructor has no arguments, so it is unclear how a non-trivial number of properties would be usefully initialized. For a trivial number of properties duplicating the initialization code is not a great burden especially if you use a helper.
I have never used a constructor preferring the more direct object construct. Faced with the same problem I might go for an inner helper for the basic object creation and wrapping helpers to assign extra properties.
As you indicate, to make cascaded constructors work there would need to be a new constructor call syntax to enable an outer constructor to delegate to an inner constructor. Rather than "call new AClass()" I would suggest that "AClass();" or perhaps "result();" should be adequate.
Please raise a Bugzilla if you feel that this extra syntax sugar is really useful.
Regards
Ed Willink
[Updated on: Wed, 02 February 2022 17:35] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04341 seconds