gmethvin / directory-watcher

A cross-platform Java recursive directory watcher, with a JNA macOS watcher and Scala better-files integration
Apache License 2.0
264 stars 34 forks source link

Define a minimal public API #73

Open gmethvin opened 3 years ago

gmethvin commented 3 years ago

It would make sense to separate the public API from other libraries used internally. This way it's clear to users which API they should be using, and we can minimize breaking changes only to that API.

The following things should be public:

  1. A builder for the DirectoryWatcher that provides all configuration functionality. As part of this we could possibly make DirectoryWatcher an interface, but I'm not sure that's really necessary if we make the constructor private. I don't see a use case for alternative implementations.
  2. DirectoryChangeEvent. This could possibly be an interface to make it easier to restructure the class hierarchy in the future.
  3. The DirectoryChangeListener interface.
  4. The FileHasher interface and some built-in implementations—but not the underlying implementation classes.
  5. A FileHash interface that defines a minimal API for file hashes and utility methods for creating FileHash instances.
  6. The MacOSXListeningWatchService and related classes. We might be able to extract some interfaces to minimize the public API here as well.

The remainder of the classes could either be made package-private or moved to an internal package. I think the latter might be more convenient.