From the course: Go Design Patterns

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Factory pattern overview

Factory pattern overview - Go Tutorial

From the course: Go Design Patterns

Factory pattern overview

- [Instructor] In this example, we're going to look at the factory design pattern, which is also fairly common in software development today. This particular pattern defines a way for a program to create objects at runtime without having to specify the exact class or type of the object to be created. This allows us to decouple the creation of an object from the definition of the object itself. This approach has some advantages. For example, it's useful in scenarios where the factory method can produce more readable code when there are multiple different ways of creating an object. In using this approach, it is also possible to create objects without having to know their exact type beforehand. Your code simply specifies some parameters and then the right type of object is created. So let's take a look at the diagram for the factory pattern. There's a creator interface that defines a factory method, which ensures that the…

Contents