Created
February 2, 2020 07:04
-
-
Save farhadmpr/b9b462dc6da87e15272f79388f7aaf69 to your computer and use it in GitHub Desktop.
Replace Conditional Statements (IF/ELSE or SWITCH) With Polymorphism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Handler | |
{ | |
public void increaseSpeed(GameObject go1) | |
{ | |
if(typeOf(go1) == Rabbit ) | |
{ | |
// increase speed by 3 | |
} | |
else if(typeOf(go1) == Bear) | |
{ | |
// increase speed by 2 | |
} | |
else if(typeOf(go1) == Turtle) | |
{ | |
// increase speed by 1 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment