3 ms·
What exactly is the bad idea here? Having more than one method in a duck-type?
by limmeau 16y ago
What exactly is the bad idea here? Having more than one method in a duck-type?
- steveklabnik 16y agois_a? and respond_to? are code smells.
- limmeau 16y agoYes, I agree. I wasn't actually suggesting to sprinkle instanceof-checks throughout the code. What I was trying to get to: if you accept the existence of single-method ducktypes (like "things that have a walk() method" oder "things that have a quack() method"), then by intersecting these concepts, you arrive at things just like interfaces, whether you call them interfaces or not. If you want the pond system to work with your two-legged bird-sound robot, you perform the same mental steps as when implementing an interface. Hence, ducktypes could be seen as interfaces without an instanceof-operation.