Created
December 29, 2015 18:51
-
-
Save codinko/246497f4482d87574510 to your computer and use it in GitHub Desktop.
FactoryMethodPattern
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
public abstract class MazeGame { | |
public MazeGame() { | |
Room room1 = makeRoom(); | |
Room room2 = makeRoom(); | |
room1.connect(room2); | |
this.addRoom(room1); | |
this.addRoom(room2); | |
} | |
abstract protected Room makeRoom(); | |
} | |
public class MagicMazeGame extends MazeGame { | |
@Override | |
protected Room makeRoom() { | |
return new MagicRoom(); | |
} | |
} | |
public class OrdinaryMazeGame extends MazeGame { | |
@Override | |
protected Room makeRoom() { | |
return new OrdinaryRoom(); | |
} | |
} | |
MazeGame ordinaryGame = new OrdinaryMazeGame(); | |
MazeGame magicGame = new MagicMazeGame(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment