NetBeans code templates for Builder Pattern

Here’s a couple of handy code templates (short cuts) for developing classes that use the Builder pattern.

This first one creates the Builder inner class itself. I’ve used the abbreviation “pscB” for this (Public Static Class Builder) –

public static class Builder {
    public Builder() {
    public ${Type} build() {
        ${Type} result = new ${Type}();
        return result;

And this one will simplify creating a “setter” field within the Builder, I use the abbreviation “psBB” for this –

public Builder ${field}(${Type} ${field}) {
    this.${field} = ${field};    
    return this;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s