If your template has lots of ifs about what kind of models you have you may want to generisize the display portion.
One example is that instead of this:
class Car
def url
DisplayModule.display_url(self)
end
end
class Motorcycle
def url
DisplayModule.display_url(self)
end
end
module DisplayModule
def display_url(vehicle)
if vehicle.class == Car
"https://repo.com/car.png"
else if vehicle.class == Motorcyle
"https://repo.com/motorcycle.png"
end
end
end
You would be better off with this:
class Car
def url
DisplayModule.display_url("car.png")
end
end
class Motorcycle
def url
DisplayModule.display_url("motorcycle.png")
end
end
module DisplayModule
def display_url(file_path)
"https://repo.com/#{file_path}"
end
end
The code is functionally equivalent but you remove one if
clause and now the display module's complexity does not need to grow if
we add another type of vehicle.