Extending an existing builder class
To extend an existing builder class, use the following syntax:
class MyExtendedBuilder extends SomeExistingBuilder {
construct() {
...
}
...
function someNewFunction() : MyExtendedBuilder {
...
return this
}
...
}
The following MyPersonBuilder class extends the existing PersonBuilder class. The existing PersonBuilder class contains methods to set a home phone number and mobile phone number. The new extended class contains a method to set the person’s alternative phone number. As there is no static field for the properties on a type, you must look up the property by name. Note that you must first define the new property in the data model.
uses gw.api.databuilder.PersonBuilder
class MyPersonBuilder extends PersonBuilder {
construct() {
super( true )
}
function withAltPhone( testname : String ) : MyPersonBuilder {
set(Person#AltPhone, testname)
return this
}
}
The PersonBuilder class has two constructors. This code sample uses the one that takes a Boolean that means create this class withDefaultOfficialID.
Another more slightly complex example
would be if you extended the Person
object and added a new PreferredName
property. In this case, you might want to extend the PersonBuilder class also and add
a withPreferredName method
to populate that field through a builder.
