Site icon Golang Libraries, Apps, Golang Jobs and Go Tutorials

Golang Prototype Factory Design Pattern

Golang Software Architecture Tutorial

In a previous factory pattern blog of the same author, he showed different ways to create an object and in this blog, we’ll look into how to prototype.

With the continuation of the factory patterns series adding this as the last blog into this design pattern.

When To use the Prototype Factory Design Pattern?

When you have to create a lots of very similar objects where you’ve some default data to be added while creating those objects.

Scenarios in Golang

Continuing with the same example of employees as in the earlier blogs where you have to create multiple Employee struct and you have the position and the annual income selected from some table or somewhere.

So in this case what’s effective is the prototype factory in which we have objects configured and the factory function which will operate a return us a particular configured object.

Let’s understand it with the code implementation by creating an Employee struct

Exit mobile version