Create a structural type with getters, setters, and methods
About this task
To create a structural type, you perform the following general steps:
Procedure
- In the package for your new type, create a Gosu class file with a .gs file extension.
-
In the Gosu editor, change the word
classtostructure. -
Just as you would declare on an interface,
add property declarations and method signatures:
- To provide data from a variable or property on an instance of this type, use
property getter
syntax:
property get PROPERTY_NAME() : TYPE - To set the value of a variable or property on an instance of this type, use
property setter syntax:
property set PROPERTY_NAME(TYPE) - To provide a callable method on an instance of this type, use the syntax:
public function METHOD_NAME(ARG_LSIT) : TYPE
- To provide data from a variable or property on an instance of this type, use
property getter
syntax:
Example
package docs.example
structure DemoStructure{
property get Name() : String
property set Name(n : String)
public function count(s : String) : double
}This example declares a structural type called DemoStructure that has the following features:
Nameproperty of typeString- count method, which takes one
Stringparameter and returns adoublevalue
What to do next
See also
