Design patterns. builder ?

346 views
Skip to first unread message

alex-coder

unread,
Mar 31, 2021, 8:26:20 AM3/31/21
to golang-nuts
Hi All,

I'm a novice to golang. 
looking for a commercial example of implementing the builder pattern
in the context of the absence of dynamic dispatching in golang.

Thank you.

alex-coder

unread,
Mar 31, 2021, 9:55:48 AM3/31/21
to golang-nuts
Even not commercial but rather industrial. I have found at least 4 educational already.

Thank you.

alex-coder

unread,
Apr 1, 2021, 2:40:21 AM4/1/21
to golang-nuts

Brian Candler

unread,
Apr 1, 2021, 3:20:52 AM4/1/21
to golang-nuts
The builder pattern generally isn't needed in go, because go has flexible struct literals where you can omit any members you don't want. 

You can implement it if you like, but it just adds a layer of boilerplate:
But if you look at the standard library as a source of inspiration and good practice, complex configuration is typically done via structs.  See for example http.Server

Robert Engels

unread,
Apr 1, 2021, 9:29:14 AM4/1/21
to Brian Candler, golang-nuts
The Go protobufs impl uses the builder pattern. 

On Apr 1, 2021, at 2:21 AM, Brian Candler <b.ca...@pobox.com> wrote:

The builder pattern generally isn't needed in go, because go has flexible struct literals where you can omit any members you don't want. 
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/39e38cd7-93ee-4084-89e4-a22bcd1baaa6n%40googlegroups.com.

alex-coder

unread,
Apr 3, 2021, 7:13:39 AM4/3/21
to golang-nuts
Hi, 
thank you for  everyone!

The main point here is: "generally isn't needed", but sometimes structure does not come described properly in some kind of string representation. :-)
the pair Func / funchandler - just excellent ! 
But what about other GO-4 patterns, I mean "isn't needed in go" ?
Where take a look at ?

Thank you.

alex-coder

unread,
Jan 12, 2023, 2:58:43 PM1/12/23
to golang-nuts
Hi All !

In case some one is in interest of the builder patterm industrial implementation.
So, I have found that there are a very intresting use the package  named https://github.com/spf13/cobra.
The package should be considered In context of the builder pattern implementation for realizaton of the template pattern to implement command/fasade pattern.
And to say everything above a little bit simpler: package is used to build CLI.
Sorry, English is not native for me. :-)

Thank you.

суббота, 3 апреля 2021 г. в 14:13:39 UTC+3, alex-coder:
Reply all
Reply to author
Forward
0 new messages