课程: Go Design Patterns

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Builder pattern overview

Builder pattern overview - Go教程

课程: Go Design Patterns

Builder pattern overview

- [Instructor] The builder pattern is a very common creational design pattern. Its main purpose is to encapsulate and simplify the creation of complex objects, which makes it much easier to create objects that can have many different representations. It also helps to make the construction code more readable, which is really helpful when the objects constructor has a lot of optional parameters or parameters of the same type. And since the object isn't actually constructed until the builder creates it, the problem of having an object be in an inconsistent or invalid state can be prevented. This kind of pattern is useful in scenarios where the object being created has a complex API with many different constructors or properties and where there's a diversity of valid states that the object can be in, depending upon the values of those properties. Using a builder pattern is pretty straightforward. We have a director object,…

内容