I'm really searching for the answer to this. I want to create a generic piece of code that just walks a directory tree. Maybe it's just a static class that contains one method. No problem for that. For each file that is not a directory, it does something. I thought that defining an interface for this something was the thing to do (I call it FileActionInterface.performAction()
for now), but I'm not sure how to code the directory walker code to call this interface method (which doesn't exist yet). I've seen and used other Java classes that have a method that says "add Interface handler()" then that class will run your implemented interface. If you drop nothing in, nothing happens.
Sorry about grasping for the right words here. How do I code this directory walker code to call the abstract code?
PS All of these are good answers and I've marked them as such. How do they do it when a class has a "addInterfaceHandler()" like method to the class? I'm guessing that the class has it's own implementation of the interface, but it's empty possibly. Then when you call the add() method you either replace the class' implementation or add to it like an array of interface implementations.
I'll start trying out your different solutions.