Skip to content

Instantly share code, notes, and snippets.

@farhadmpr
Created February 2, 2020 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farhadmpr/b9b462dc6da87e15272f79388f7aaf69 to your computer and use it in GitHub Desktop.
Save farhadmpr/b9b462dc6da87e15272f79388f7aaf69 to your computer and use it in GitHub Desktop.
Replace Conditional Statements (IF/ELSE or SWITCH) With Polymorphism
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