In software engineering, the Singleton pattern is a software design pattern that restricts the instantiation of a type to one object. This is useful when exactly one object is needed to coordinate actions across the system. In this article, we will d...

Markdown supported · ⌘↵ to post
masood keshvari
Backend developer | Golang
Hi and thanks to share this blog post. I have two questions: 1) In this example, you use private variable, why you don't expose it? in other word what difference between exposed and unexposed variable in this pattern? In my opinion when we expose it, other pkg can use it with nil value and as a result the application panics. is that the reason we use unexposed variable?
2) what happening if we don't expose type Singleton? In this example Singleton type is exposed, other pkg can create instance from Singleton type directly and as a result we have many instance from Singleton type.
thanks Matthias