Sunday, 18 August 2013

How to decide which conditions to keep and which conditions to dissolve into polymorphism

How to decide which conditions to keep and which conditions to dissolve
into polymorphism

A brief reference:
http://www.refactoring.com/catalog/replaceConditionalWithPolymorphism.html
To clarify my question:
There are too many articles on the internet which talk about using
polymorphism instead of inheritance. If this were true then 'if-elses' and
'switches' should not appear in most of the java code.
The fact that they do either means:
There are certain cases where conditionals cannot be transformed into
polymorphism.
Each of the code with if else had a potential to be refactored but they
were not done.
Now my question.
Which of the above option is true ?
If option 1 is true then 'how to decide if the if-else can be substituted
by polymorphism' ?

No comments:

Post a Comment