Skip to content

Golang Builder Pattern

April 7, 2014

The builder pattern should prove very useful since the problem it solves is more difficult in the Go language. The builder pattern was created to prevent the constructor telescoping anti-pattern in languages like Java, C++, etc. But you can’t write that anti-pattern in Go because the language doesn’t allow method/function overloading. So in a Go “package” if you have some kind of constructor typically ‘func New(someArgs…)’ that’s the only instance of ‘New’ you can have in that package.

The builder pattern gives you an alternative mechanism to construct things with numerous varieties and control over the outcome. Below is my example of how this pattern might work in Go:

Advertisements

From → Golang

Leave a Comment

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: