Home > Computing > NetBeans code templates for Builder Pattern

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;
    }
    
    ${cursor}
}

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;
}
Advertisements
Categories: Computing
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: