Showing constructors on class diagrams.

2,822 views
Skip to first unread message

rgsheehan

unread,
Jul 11, 2012, 4:11:00 PM7/11/12
to sparx-enterprise-archite...@googlegroups.com
Hello all,
It seems trivial, but I have apparently forgotten how to get EA to show constructor/destructors on class diagrams.  I actually have a model stub that shows them, but all my new classes do not, even though they show any other operations and attributes I create for the class.  So three questions:
1. How to get constructor displayed on class diagrams.
2. Why would EA not show them by default?
3. Where could I have found the answer to this in the so-called 'Help' documentation.


Thanks in advance.

R. G. Sheehan

[original message]

qwerty

unread,
Jul 11, 2012, 4:59:00 PM7/11/12
to sparx-enterprise-archite...@googlegroups.com
You can only show them if you have defined them as operation. To show the operations compartment check the diagram properties: Elements/Operations.

q.

[original message]

SomersetGraham

unread,
Jul 12, 2012, 3:28:00 AM7/12/12
to sparx-enterprise-archite...@googlegroups.com
Hi
There is an option the settings for code engineering that specifies if a constructor/destructor is generated when code for the class is generated.
Reverse engineering will the of course add the operations to you class

[original message]

rgsheehan

unread,
Jul 12, 2012, 9:02:00 AM7/12/12
to sparx-enterprise-archite...@googlegroups.com
SomersetGraham,

Yes, the approach you suggested works.  Thank you.  Not sure what Sparx is thinking here.  It sure seems to me to be a convoluted, roundabout, non-intuitive approach to what would arguably be a primary usage of the tool.

Anyway, thanks again.

R. G. Sheehan

[original message]

SomersetGraham

unread,
Jul 12, 2012, 9:10:00 AM7/12/12
to sparx-enterprise-archite...@googlegroups.com
Well the code generation only makes a default constructor which is not always what you want
You can define more constructors using the operations page

[original message]

Schollii

unread,
Oct 18, 2017, 4:23:00 PM10/18/17
to Sparx Enterprise Architect General
I agree, but not every OO language has a constructor. For example Python (supported by EA) has initializers which are similar but not identical to C++ constructors. Initializers in Python are intuitively an operation (self exists and gets extended with attributes). It is not so intuitive to think of constructors as operations but really they are: they are just a way to setup the initial state of the instance, and there can be many (overloads) of them (which emphasizes that an operation is the right way to think about a constructor). 
Reply all
Reply to author
Forward
0 new messages