Stephan van Hulst wrote:Well, why do you need a base class (I'm assuming it's Cardholder?) and what functionality are your other classes going to add to it? It's not very clear from your example.
Can you explain what CardHolder does that wouldn't be available in a List<PlayingCard>?
Stephan van Hulst wrote:Well, the Deque interface really already specifies most of this behaviour. You could just use the LinkedList class, which implements both the List and the Deque interfaces.
What you could do is define a static method in your Card class that returns a LinkedList<Card> containing the standard 52 cards.
If you're really looking to get the exercise, you can declare your CardHolder class to implement java.util.List<Card> and java.util.Deque<Card>, and implement all the methods yourself. You can also extend AbstractList<Card> to get you started.
This way, you will only have one class (CardHolder), and let the card games that use CardHolders (for instance, as decks, discard piles or hands) be responsible for using them correctly.
Stephan van Hulst wrote:Well, I don't really want to be a party pooper, but my point is that CardList really doesn't add anything that LinkedList doesn't already have. The only difference is that you check for null elements, and you don't allow duplicates. The former is good, but you shouldn't restrict duplicates from being added to your class (some card games, like Canasta, shuffle two or even three standard decks together).
So really, all that your class does is check for null elements. Your design would be a lot cleaner if you just dropped the class completely, and let specific card games keep track of their own LinkedList<Card>, and make them responsible for not adding any null elements to it.
Here's an example of what I mean. Here, the game is responsible for maintaining all the cards: