Fire and forget pattern

--

Came an interesting pattern in code base and thought would share.

For analytics tracking, tracking code usually ends within the scope it is triggered (function or block).

We need not hold reference to any objects.

As such, the code such as this makes sense:

instead of :

But holding on to a single instance becomes useful when we need to configure the object variables:

Other Drawbakcs:

  • Imagine if the methods are called several times in a short duration.
    This would cause several transient objects to be created impacting performance.

Thanks for reading!

--

--