snowplow / snowplow-java-tracker

Snowplow event tracker for Java. Add analytics to your Java desktop and server apps, servlets and games. (See also: snowplow-android-tracker)
http://snowplowanalytics.com
Apache License 2.0
24 stars 36 forks source link

Standardise API for Tracker and Subject Builders #302

Closed mscwilson closed 2 years ago

mscwilson commented 2 years ago

The Builder pattern is used extensively in the Java tracker. However, two different styles are implemented. For example:

Style 1:

Tracker tracker = new Tracker.TrackerBuilder(emitter, namespace, appId).build();

There is a TrackerBuilder nested class.

Style 2:

BatchEmitter emitter = BatchEmitter.builder().url(collectorEndpoint).build();

There are Builder and Builder2 nested classes.

Tracker and Subject use Style 1. Emitters and Events (PageView, etc) use Style 2. This isn't great for usability. Style 2 code is also quite hard to follow. It would be helpful to standardise all the public API classes to use Style 1.

mscwilson commented 2 years ago

On closer inspection, the classes using Style 1 are those that do not extend an abstract class, i.e. Tracker and Subject. The classes using Style 2 inherit from AbstractEmitter, AbstractEvent, or AbstractHttpClientAdapter. So there is a certain amount of "Java being Java" going on.

It should still be possible to change the structure so the API looks the same. After nearly 4 months working on this tracker I've still had to look up how to create a new tracker component every time.