Classes
Gosu classes encapsulate data and code to perform a specific task. Typical use of a Gosu class is to encapsulate a set of Gosu functions and a set of properties to store within each class instance. A class instance is a new in-memory copy of the object of that class. If some Gosu code creates a new instance of the class, Gosu creates the instance in memory with the type matching the class you instantiated. You can manipulate each object instance by getting or setting properties. You can also invoke the Gosu functions of the class. Gosu functions defined in a class are also called methods.
You can extend an existing class, which means to make a subclass of the class with new methods or properties or different behaviors than existing implementations in the superclass.
Gosu classes are analogous to Java classes
in that they have a package structure that defines the namespace of that
class within a larger set of names. For example, if your company is called
Smith Company and you were writing utility classes to manipulate addresses,
you might create a new class called NotifyUtils
in the namespace smithco.utilities.
The fully qualified name of the class would be smithco.utilities.NotifyUtils.
You can write your own
custom classes and call these classes from within Gosu, or call built-in
classes. You create and reference Gosu classes by name just as you would
in Java. For example, suppose you define a class called Notification in package smithco.utilities with a method
(function) called getName().
You can create an instance of the class and then call a method like this:
// Create an instance of the class
var myInstance = new smithco.utilities.Notification()
// Call methods on the instance
var name = myInstance.getName()
You can also define data and methods that belong to the class itself, rather than an instance of the class. You use this technique, for instance, to define a library of functions of similar purpose. The class encapsulates the functions but you never need to create an instance of the class. You can create static methods on a class independent of whether any code creates an instance of the class. Gosu does not force you to choose between the two design styles.
You can write Gosu classes that extend from Java classes. Your class can include Gosu generics features that reference or extend Java classes or subtypes of Java classes.
Guidewire Studio
To create and manage Gosu classes, Guidewire recommends that you always use Guidewire Studio.
See also
