我想弄清楚如何在不同的類中使用枚舉來擴展一個通用的抽象類。抽象類中的枚舉
簡單的例子:
卡類
public class Card {
private String name;
private String value;
private String suit;
public Card(String name, String value, String suit) {
this.value = value;
this.suit= suit;
}
}
摘要DECK類
public abstract class Deck {
private enum SUITS{
}
private enum VALUES{
}
private int cardNumber;
private ArrayList<Card> cardList;
public Deck(VALUES valori,SUITS semi){
ArrayList<Card> clist = new ArrayList<>();
for (SUITS s: semi.values()){
for (VALUES v: valori.values()){
cardList.add(new Card(v.toString(),s.toString()));
}
}
cardNumber = cardList.size();
}
類BriscolaDeck
public class CarteBriscolaDeck extends Deck {
private enum SUITS{
COPPE,
DENARE,
BASTONI,
SPADE
}
private enum VALUES{
ASSO,
DUE,
TRE,
QUATTRO,
CINQUE,
SEI,
SETTE,
FANTE,
CAVALLO,
RE
}
public CarteBriscolaDeck(){
super(VALUES,SUITS);
}
}
類PokerDeck
public class PokerDeck extends Deck {
private enum SUITS{
SPADES,
HEARTS,
DIAMONDS,
CLUBS
}
private enum VALUES{
ACE,
TWO,
THRRE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING
}
public PokerDeck(){
super(VALUES,SUITS);
}
}
我這樣做對嗎?有沒有可能優化?
預先感謝您。
提示:請讓我知道我的答案是否適合您;或者如果有什麼你會尋找;否則考慮接受最適合的答案來表明「你有你需要的東西」。 – GhostCat