3 ms·
I don’t think that I’ve missed the author's point; but any time I see an if statement and polymorphic code used near each other, I question whether or not the p
by noblethrasher 16y ago
I don’t think that I’ve missed the author's point; but any time I see an if statement and polymorphic code used near each other, I question whether or not the programmer understands OOP. His example is not exactly using polymorphic code, but he is basically dispatching based on the runtime type.
We know that a method that accepts parameters that are reference types should check to see if they are null. Since instance methods cannot check their first parameter (the this pointer), we make it impossible for outside code to call instance methods. Now callers never have to worry about the runtime type of an object or whether or not it’s null.
If you’re going to circumvent the type system with explicit casts then, of course, you’re going to get invalid cast exceptions, but that’s for the client code to deal with.