Methods; specifically pointer receivers. Using a value will create copies
of the struct on every method call whereas pointers will use the same
struct.

Another benefit is to optionally do an atomic swap or use a mutex guard if
you wanted to change the instance at runtime (eg config reloads).

Personally I've come to the realisation that the singleton pattern is one
of the worst design patterns. I abused it a lot early in my career because
of its short-term convenience factor. However in OO terms it fails SOLID.
In testing terms it's a PITA to work with as it requires that all tests run
serially and have a "setup" or "teardown" that ensures the singular
instance is reset to a well known state.

Better to use a factory method and have the class package local/private
(which isn't great practice). Even then I still feel it's a bad pattern
because it becomes very complex to stub out and doesn't make dependencies
explicit.
On Fri, 1 Jul 2016 at 08:14, <krmaya...@gmail.com> wrote:

> does the singleton variable for any reason need to be a pointer ?
>
>
> On Thursday, June 30, 2016 at 4:07:08 PM UTC-7, Nathan Fisher wrote:
>
>> I often put all of my wire-up in main which ensures that it's only one
>> instance. Then I create a struct that all of the dependencies hang off of
>> like loggers and clients.
>>
> On Thu, 30 Jun 2016 at 23:30, Val <dele...@gmail.com> wrote:
>>
> Indeed.
>>> I find it weird that the authors care more about lazy init (not strictly
>>> required for singletons) than about ensuring properly that multiple
>>> instanciation cannot happen.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>>
>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to golang-nuts...@googlegroups.com.
>>
>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to