Skip to content

Instantly share code, notes, and snippets.

@semanticer
Created March 10, 2016 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semanticer/0592b901e15f698da90c to your computer and use it in GitHub Desktop.
Save semanticer/0592b901e15f698da90c to your computer and use it in GitHub Desktop.
Basic example of builder for poker hand
public class Hand {
public final Card firstCard;
public final Card secondCard;
public Hand(Card firstCard, Card secondCard) {
this.firstCard = firstCard;
this.secondCard = secondCard;
}
}
/** builder for Hand **/
public class HandBuilder {
private Card first;
private Card second;
HandBuilder first(Card first) {
this.first = first;
return this;
}
HandBuilder second(Card second) {
this.second = second;
return this;
}
public Hand build() {
return new Hand(first, second);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment