From the course: Go Design Patterns
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Builder pattern example - Go Tutorial
From the course: Go Design Patterns
Builder pattern example
- [Instructor] For this example, we're going to use the builder pattern to create a notification object, which represents the kind of notification pop-up message you might see on your phone or desktop computer. The notification 'Go file' contains the definition of the notification struct that the builder will create. Note that all the fields are lowercase, which means that they are not exported from this struct which makes the notification type effectively immutable, unless you provide methods to change the fields, which I haven't. So this is one of the advantages of using a builder. You can make the finished object immutable pretty easily. All right, so now let's take a look at the builder code. Here in the builder.Gofile I have the notification builder struct along with several methods that are used to modify the builders properties and a function named new notification builder. And if I scroll down a bit, we can see…
Contents
-
-
-
-
(Locked)
Builder pattern overview1m 52s
-
(Locked)
Builder pattern example9m 58s
-
(Locked)
Factory pattern overview1m 40s
-
(Locked)
Factory pattern example6m 12s
-
(Locked)
Singleton pattern overview2m 10s
-
(Locked)
Basic Singleton pattern example3m 17s
-
(Locked)
Making Singleton concurrent-safe3m 44s
-
(Locked)
-
-
-