Duck typing using RTTI
"When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck."
– James Whitcomb Riley
Clear, isn't it? What may not be so clear is that this approach can also be used in computer programming. Yes, even without an actual duck!
Note
For design patterns lovers, duck typing is the smartest way to achieve the Visitor pattern goal.
Getting ready
Referring to duck typing, Wikipedia (http://en.wikipedia.org/wiki/Duck_typing) gives the following explanation :
"In computer programming with object-oriented programming languages, duck typing is a style of typing in which an object's methods and properties determine the valid semantics, rather than its inheritance from a particular class or the implementation of an explicit interface."
How can all these concepts be used in everyday programming? This is the question that this recipe aims to answer.
Let's say that you have a form, and you want to inform the user that something bad happened...