Created
March 10, 2016 08:32
-
-
Save semanticer/0592b901e15f698da90c to your computer and use it in GitHub Desktop.
Basic example of builder for poker hand
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
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