Skip to content

Instantly share code, notes, and snippets.

@MeetMartin
Created October 29, 2020 21:21
Show Gist options
  • Select an option

  • Save MeetMartin/b264322b6c8b41be311980cd3e5f86a9 to your computer and use it in GitHub Desktop.

Select an option

Save MeetMartin/b264322b6c8b41be311980cd3e5f86a9 to your computer and use it in GitHub Desktop.
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