Skip to content

Instantly share code, notes, and snippets.

@JeffML
Created March 18, 2017 21:13
Show Gist options
  • Save JeffML/cf18a094b0f9dc84838cdc1e71691f59 to your computer and use it in GitHub Desktop.
Save JeffML/cf18a094b0f9dc84838cdc1e71691f59 to your computer and use it in GitHub Desktop.
BowlingBallFactory
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