Created
February 2, 2020 07:17
-
-
Save farhadmpr/9b0da3b20f80480ada0d99c12a23769d 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
Interface GameObject() { | |
increaseSpeed() {}; | |
} | |
class Rabbit implements GameObject { | |
increaseSpeed() { | |
//increase speed by 3 | |
} | |
} | |
class Bear implements GameObject { | |
increaseSpeed() { | |
//increase speed by 2 | |
} | |
} | |
class Turtle implements GameObject { | |
increaseSpeed() { | |
//increase speed by 1 | |
} | |
} | |
class Handler { | |
public void increaseSpeed(GameObject go1) { | |
go1.increaseSpeed(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment