Create and implement an interface

Procedure

  1. To create an interface in Guidewire Studio, first create an appropriate package.
    1. Right-click the package folder, and then click the New submenu.
    2. Click Class to create the class in that package.
    3. Type a name for the interface.
    4. In the drop-down list, click Interface.
      Studio creates a new interface with the appropriate syntax.
  2. 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
    }
  3. To implement an interface, create a Gosu class and add "implements MyInterfaceName" after the class name.
    For example, if your class is called MyRestaurant, go to the line:
    class MyRestaurant
  4. Change that line to:
    class MyRestaurant implements Restaurant
  5. For the example Restaurant interface, 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."
      }
    }