A part of the functionality I'm putting into my program is comparing two files to check if they are equal. This can be done in a bunch of ways, eg. comparing bit by bit, by checksum, by date+size etc... I'd like to enable the user to choose which of these should be used, and it shouldn't be too hard to put new ways into the program.
So what would be a good way to do it? There should be one function (or class?) that will delegate the work to the "modules" that actually compare by different ways, depending on which of those the user chooses (a parameter to the function).
How to implement the modules? I thought maybe an abstract "Comparator" class with a virtual function that can compare two files, and each "way to compare" would subclass it and implement its stuff in that function. But it seems kinda strange to have to create an instance of the comparator just to compare two files and then throw it away.
A simpler way would be just to write a bunch of functions that the delegate would call, but that doesn't seem to be a "clean" way to do it in an object-oriented language, but so far it seems like the better idea.