Go (Golang) Functional Options Pattern

preview_player
Показать описание
Go (Golang) Functional Option Design Pattern

The Functional Options pattern is pretty useful when building Go packages that need to be configured with different and varying configuration options. One of the ways you could configure that is by using a Config struct or some other pre-defined package level structs. Although that works it's not as elegant and robust as the Functional Option pattern which allows you to build countless extensions to your package functionality without breaking its public APIs (method definition and interfaces)

Рекомендации по теме
Комментарии
Автор

This is beautiful! I should create a design pattern series as well. Love your channel, you always talk about things that I often overlook from my day job :)

GolangDojo
Автор

thnaks for this. learning day by day with your videos.

opeyemipopoola
Автор

Came for Go, stayed for VIM.. you must do a video on your vim setup

canopusinthenorth
Автор

Great pattern.
I want to emphasize to define the `Option` type. So on godoc, all functional options are grouped under `Option` type.

nicolasparada
Автор

What are the advantages and disadvantages over builder pattern? 🤔 Cause you know we are using closures in here which are technically objects which have state + a method for closure call, so why not put those states in builder object? Oh I see, this one is more dynamic, we can compose different options array at runtime, it requires another layer or something to do it in builder pattern... It was nice then :)

TheKhanj
join shbcf.ru