Creating constructors
Constructors are called when a class is instantiated.
Procedure
- In the model browser, right-click a class to open the pop-up menu.
-
Select Add New > Constructor
The Constructor Arguments window is displayed.
- Use the controls to add the arguments you want to use for the constructor.
-
Click OK to close the Constructor Arguments
window.
The new constructor can now be seen beneath the class in the browser (in the Operations category).
- Double-click the new constructor to open the Features window.
- On the Implementation tab of the Features window, enter the body for the constructor.
-
If you want to add initializer code, go to the General tab of the
Features window and use the Initializer field.
Note: You can also create a constructor by using the controls on the Operations tab of the Features window for a class, or by selecting the relevant option in the pop-up menu for classes that are displayed in a diagram.