Adding Methods to a Class
This chapter discusses how to add and edit method definitions in a class definition.
You can add a new method to a class definition in two ways:
To add a method using the Class Editor, position the cursor on a blank line in the Class Editor and enter a method declaration such as:
Class MyApp.Person Extends %Persistent
Method NewMethod() As %String
Alternatively, you can do this by copying and pasting an existing method declaration and then editing it.
You can invoke the New Method wizard by selecting
. Alternatively, right-click the Class Inspector and select
. You can also click the New Method
from the toolbar.
The New Method wizard prompts you for information. Click Finish
at any time (default values are provided for any information you have not specified).
The New Method wizard prompts you for the following information (you can later modify any of these values):
(required) Name of the new method. This name must be a valid method name and must not conflict with the name of a previously defined method.
(optional) Description of the new method. This description is used when the class' documentation is displayed in the online class library documentation.
Every method has a signature that indicates its return type (if any) as well as its formal argument list (if any). For a method signature you may specify the following:
(optional) Indicates the type of the value returned by this method. This type is the name of an InterSystems IRIS class. You can type this name in directly or choose from a list of available classes using the Browse
For example, a method that returns a true (1) or false (0) value would have a return type of %Boolean
. Leave this field empty if your new method has no return value.
(optional) Indicates the names, types and default values of the method's formal arguments along with how data is passed (by reference or by value). The arguments are displayed in order in a table. You can add a new item to the argument list by clicking the Add
located on the side of the table. This displays a popup dialog allowing you to specify the name of the argument, its type, its optional default value, and whether it is passed by value or by reference. Using the other buttons, you can remove and rearrange the order of items in the list.
You may specify additional characteristics for your method. These include:
(optional) Indicates whether this method is public or private. Private methods can only be invoked from other methods of the same class.
(optional) Indicates whether this method is final. Final methods cannot be overridden by subclasses.
(optional) Indicates that the new method is a class method (as opposed to an instance method). Class methods may be invoked without having an object instance.
SQL Stored Procedure
(optional) Indicates that this method is accessible to an ODBC or JDBC client as a stored procedure. Only class methods may be projected as SQL Stored Procedures.
If you want, you may enter the implementation (code) for the new method by typing lines of source code into the Class Editor. You can also enter this source code after running the wizard.
After running the New Method wizard, the Class Editor is updated to include the new method definition. You can edit it using either the Class Editor or the Class Inspector. For example:
/// This is a Person class
class MyApp.Person extends %Persistent
Method Print() As %Boolean
submenu is available only when Studio is connected to a Windows server. The Override
menu item is available in other platforms.
One of the powerful features of object-based development is that classes inherit methods from their superclasses. In some cases, you may want to override, that is, provide a new implementation for, a method inherited from a superclass.
simplifies the process of overriding a class method by displaying a list of all the methods defined by superclasses that can be overridden by the current class.
To do this, follow these steps:
Open (or create) a persistent class definition in Studio.
and select the Methods
tab. This displays a dialog window containing a list of methods which you can override.
class MyApp.Person extends %Persistent
Method %OnValidateObject() As %Status
At this point, you can use the Class Editor to add code to the body of the method.
Content Date/Time: 2019-07-15 06:54:33