Created
October 29, 2020 21:21
-
-
Save MeetMartin/b264322b6c8b41be311980cd3e5f86a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public interface Retile { | |
| void walk(); | |
| } | |
| public class Turtle implements Reptile { | |
| @Override | |
| public void walk() { | |
| System.out.println("Turtle is walking!"); | |
| } | |
| } | |
| public class Tortoise implements Reptile { | |
| @Override | |
| public void walk() { | |
| System.out.println("Tortoise is walking!"); | |
| } | |
| } | |
| public class ReptileFactory { | |
| public Reptile getReptile(String reptileType){ | |
| if(reptileType == null){ | |
| return null; | |
| } | |
| if(reptileType.equalsIgnoreCase("TURTLE")){ | |
| return new Turtle(); | |
| } else if(shapeType.equalsIgnoreCase("TORTOISE")){ | |
| return new Tortoise(); | |
| } | |
| return null; | |
| } | |
| } | |
| public class ReptileDemo { | |
| public static void main(String[] args) { | |
| ReptileFactory reptileFactory = new ReptileFactory(); | |
| Reptile reptile = Reptile.getReptile("TURTLE"); | |
| reptile.walk(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment