You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "J. B. Rainsberger" <jb...@rogers.com> on 2004/03/09 20:45:07 UTC

Polymorphism (was Re: 'instanceof')

MNewcomb@tacintel.com wrote:

>>Somewhere you want to use an instanceof check. In general, a 
>>performs an instanceof check in an 'if' statement of some kind.
>>So apply Replace Conditional with Polymorphism [Refactoring],
>>which generally introduces a Strategy [GoF:Design Patterns] into
>>the design. Of course, I'm just guessing, but it's a pretty good
>>bet.
> 
> How would you test for specific instances of a polymorphic class in the
> view? If the view gets a Shape, no reason why the view can't test for
> Circle, Square, or ? to display a specific thing for the viewer...

Why not just invoke draw() on the Shape and let /it/ figure things out? 
That's the whole point of polymorphism. If you're just going to ask the 
object what type it is, then decide what to do with it as a result, then 
why have polymorphism at all?
-- 
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org