Imagine code that reads from a file, cleans the data and finally writes the cleaned data to a new file.
Let's briefly define these methods as Ruby stubs:
def write(filename, data)
File.open(filename, "w") do |f|
f.write(data.to_yaml)
end
end
def read(filename)
YAML.load_file(filename)
end
def clean(data)
data.map do |line|
line.strip!
end
end
We can also have an orchestrator method that triggers the whole logic:
def read_clean_write(filename)
write(filename, clean(read(filename)))
end
I think that while the isolated read, write and clean methods are modular and apply the single responsibility principle, read_clean_write is quite the opposite (and looks ugly). What is the best way to do that while keeping SRP?
read_clean_write
tocleanup!
orprettify!
or something similar. Orchestration methods are fine, and don't violate SRP, but naming them by their individual actions is not fine: the whole reason they exist is because you've identified a sequence of actions that you think of as a whole. Figure out what that "whole" thing is and name that. \$\endgroup\$