in reply to Re: replace conditionals with polymorphism
in thread replace conditionals with polymorphism
The only way you can get rid of the switch is to replace it with a object belonging to a dynamically chosen class. But how are you going to select the class? Of course with another switch statement (or other conditional logic)!Or with a naming convention, right? But then you can do that with a dispatch table as well.
I think that the main thing that OOP polymorphism gains you is that it's a kind of plug-in architecture -- you can add handling for new cases by adding a new module, without changing the existing ones.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: replace conditionals with polymorphism
by tilly (Archbishop) on Feb 10, 2009 at 03:01 UTC | |
by doom (Deacon) on Feb 10, 2009 at 04:24 UTC | |
by tilly (Archbishop) on Feb 10, 2009 at 05:58 UTC | |
by ELISHEVA (Prior) on Feb 10, 2009 at 08:16 UTC | |
by tilly (Archbishop) on Feb 10, 2009 at 15:58 UTC | |
|