Distinguishing repetitive code with the same implementation

Posted by KyelJmD on Programmers See other posts from Programmers or by KyelJmD
Published on 2012-10-22T02:02:34Z Indexed on 2012/10/22 5:15 UTC
Read the original article Hit count: 528

Given this sample code

import java.util.ArrayList;
import blackjack.model.items.Card;

public class BlackJackPlayer extends Player {

    private double bet;

    private Hand hand01 = new Hand();
    private Hand hand02 = new Hand();


    public void addCardToHand01(Card c) {
        hand01.addCard(c);
    }

    public void addCardToHand02(Card c) {
        hand02.addCard(c);
    }

    public void bustHand01() {
        hand01.setBust(true);
    }

    public void bustHand02() {
        hand02.setBust(true);
    }

    public void standHand01() {
        hand01.setStand(true);
    }

    public void standHand02() {
        hand02.setStand(true);
    }

    public boolean isHand01Bust() {
        return hand01.isBust();
    }

    public boolean isHand02Bust() {
        return hand02.isBust();
    }

    public boolean isHand01Standing() {
        return hand01.isStanding();
    }

    public boolean isHand02Standing() {
        return hand02.isStanding();
    }

    public int  getHand01Score(){ return hand01.getCardScore(); }

    public int  getHand02Score(){ return hand02.getCardScore(); }

}

Is this considered as a repetitive code? providing that each method is operating a seperate field but doing the same implementation ? Note that hand01 and hand02 should be distinct.

if this is considered as repetitive code, how would I address this? providing that each hand is a seperate entity

© Programmers or respective owner

Related posts about java

Related posts about design-patterns