Created
March 18, 2017 21:13
-
-
Save JeffML/cf18a094b0f9dc84838cdc1e71691f59 to your computer and use it in GitHub Desktop.
BowlingBallFactory
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
class BowlingBallFactory { | |
static private class BowlingBall implements IBowlingBall{ | |
private String petName; | |
BowlingBall() { | |
} | |
private void setPetName(String petName) { | |
this.petName = petName; | |
} | |
String getPetName() { | |
return this.petName; | |
} | |
} | |
IBowlingBall createBowlingBallFor(Bowler b) { | |
b.setBowlingBall(new BowlingBall()); | |
} | |
IBowlingBall createBowlingBallFor(ProShop p) { | |
p.addBowlingBall(new BowlingBall()); | |
} | |
} | |
class Bowler { | |
private BowlingBall bowlingBall; | |
Bowler(BowlingBall b) { | |
this.bowlingBall = b; | |
} | |
void setPetName(String petName) { | |
if (petName ==~ /[A-Z][a-z\s]*/) { | |
bowlingBall.setPetName(petName); | |
} else { | |
throw Exception("only letters, please") | |
} | |
} | |
String getPetName() { | |
return bowlingBall.getPetName(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment