Let's assume that I have a piece of functionality in my application which is responsible for adding a deleted marker file .deleted
in a directory that is considered to be deleted.
What would be that best way to implement this? Static function or an object with a single method that conveys this functionality? Those are my 2 options (my language isn't functional):
class MarkAsDeletedDir {
void apply(File directory) {
directory.addChild(".deleted");
}
}
Usage: new MarkAsDeletedDir().apply(dir)
or
class AppUtils {
// other stuff
// ...
static void markAsDeletedDir(File directory) {
directory.addChild(".deleted");
}
}
Usage: AppUtils.markAsDeletedDir(dir)
Assume no performance overhead in creating new objects such as the former.
MarkAsDeletedDir
implement an interface or inherit from abstract class so it can be mocked if necessary. – David Arno Oct 31 '17 at 12:04