What is duck typing?

sushil bharwani picture sushil bharwani · Nov 17, 2010 · Viewed 131.8k times · Source

I came across the term duck typing while reading random topics on software online and did not completely understand it.

What is “duck typing”?

Answer

Oded picture Oded · Nov 17, 2010

It is a term used in dynamic languages that do not have strong typing.

The idea is that you don't need a type in order to invoke an existing method on an object - if a method is defined on it, you can invoke it.

The name comes from the phrase "If it looks like a duck and quacks like a duck, it's a duck".

Wikipedia has much more information.