been reading this article on Traits in Computer programming.
The opening sentence highlights two points
- Traits both provide a set of methods that implement behaviour to a class,
- and require that the class implement a set of methods that parameterize the provided behaviour.
The behaviour that the definition talks about seems to suggest it is duck typing.
I did read What is duck typing and the following example in C++ helps with that.
template <typename T>
void f (T x) {
x.method ();
}
We have effectively parametrized the method 'f' with type 'T'. The fact that it done at compile time and not at runtime shouldn't make a difference.
As highlighted in the Wikipedia article on Traits It is not clear to me, how is a trait is different from duck typing ? Appreciate any pointers.
Thanks for your time.