Some thoughts capturing from a comment on the Telemetry module PR.
Telemetry is currently initialized with:
MapboxTelemetry telem = MapboxTelemetry.getInstance();
telem.initalize(context, accessToken, locationProvider);
I'm not a big fan of having both a getInstance and initalizer method as it defeats the purposes of those methods separately and I feel this is thread unsafe as it can lead to race conditions.
I'm thinking this can be solved in two ways:
We either change the underlying code to add parameters to getInstance and setting those as class members + referencing those solely through INSTANCE class member. An example of this in Mapbox.java
Other idea is to separate the concerns of this class into different components using a design patterns (eg. a factory pattern could serve as a wrapper around the paremeters?). This should remove the requirement of the initialization method.
cc @zugaldia
Some thoughts capturing from a comment on the Telemetry module PR.
Telemetry is currently initialized with:
I'm not a big fan of having both a
getInstanceandinitalizermethod as it defeats the purposes of those methods separately and I feel this is thread unsafe as it can lead to race conditions.I'm thinking this can be solved in two ways:
We either change the underlying code to add parameters to getInstance and setting those as class members + referencing those solely through INSTANCE class member. An example of this in Mapbox.java
Other idea is to separate the concerns of this class into different components using a design patterns (eg. a factory pattern could serve as a wrapper around the paremeters?). This should remove the requirement of the initialization method.
cc @zugaldia