Is there a name for this code design principle?
It's the #1 thing I want to convince my coworkers of
April 14, 2020
Bad
class Animal
initialize(type)
@type = type
end
def bark
return unless 'dog' == @type
puts "woof!"
end
def meow
return unless 'cat' == @type
puts "meow."
end
end
Good
class Dog
def bark
puts "woof!"
end
end
class Cat
def meow
puts "meow."
end
end
Best?
class Dog
def make_noise
puts "woof!"
end
end
class Cat
def make_noise
puts "meow."
end
end
John Bachir's Code Blog