Better developers than I have written about iceberg classes and why they are a code smell. I’d like to talk about a specific kind of iceberg class I’ve recently come across. This type involves inheritance. Here’s an example of what I mean.
class Job
def perform
# do some setup
execute
# do some cleanup
end
private
def execute
raise NotImplementedError
end
end
class SomeJob
private
def execute
# do some stuff
end
end
class AnotherJob
private
def execute
# do other stuff
end
end
My gut reaction to this code is that there is a design smell here. I’m wondering if my reaction is not because of the “iceberg” nature of the subclasses, but because of the use of inheritance. I’m curious what others think and if you agree that there is a problem with the code.