Create and implement an interface
Procedure
-
To create an interface in Guidewire Studio, first create an
appropriate package.
- Right-click the package folder, and then click the New submenu.
- Click Class to create the class in that package.
- Type a name for the interface.
-
In the drop-down list, click Interface.
Studio creates a new interface with the appropriate syntax.
-
Write the rest of the interface like
a Gosu class, except that methods are method signatures only with no
method bodies.
For example, define an interface with the following code:
interface Restaurant { function retrieveMeals() : String[] function retrieveMealDetails(dishname : String) : String } -
To implement an interface, create a Gosu class and add "
implementsMyInterfaceName" after the class name.For example, if your class is calledMyRestaurant, go to the line:class MyRestaurant -
Change that line to:
class MyRestaurant implements Restaurant -
For the example
Restaurantinterface, implement the interface with a class.For example, use code like the following lines:class MyRestaurant implements Restaurant override function retrieveMeals() : String[]{ return {"chicken", "beef", "fish"} } override function retrieveMealDetails(dishname : String) : String { return "Steaming hot " + dishname + " on rice, with a side of asparagus." } }
