I have recently discovered that VB.NET already* supports duck typing and without resorting to generics too boot. The solution is purely dynamic, just like with Ruby. Here's the analogous code sample I've been using in my other post about duck typing:
Class Customer
Dim _first_name, _last_name As String
Public Sub New(ByVal first_name As String, ByVal last_name As String)
_first_name = first_name
_last_name = last_name
End Sub
Public Sub append_name_to_file(ByVal file)
file &= _first_name & _last_name
End Sub
End Class
I used different operator here (&) but the point is that file parameter has no type declared, is not implicitly treated as Object and is dynamically checked for existence of said operator (&). Quite cool.
*Tested with Visual Studio 2005 which will be available in 7 weeks. I think this won't work in 2003 (at least not in this manner).
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5