I would like to write a data structure implementation in Java that uses caches as a core part of its functionality, and I would like the user to be able to provide their own cache implementations that implement a particular cache interface so they can test performance using various strategies (like LRU, LFU, MRU, etc.).
What is the best way to allow a user to swap in their own cache in an instance of one of the data structures without giving them access to my codebase? Is there a way I can pass in a class that implements the cache interface as a parameter?
This structure will contain perhaps several caches arranged in different ways, so I would need more than one instance of a cache, and I would like to be able to create and destroy caches at runtime. Would passing a constructor to the cache as a Lambda function be a good solution?