Jon
Campbell Ritchie wrote:We have already seen that Deck extends Class is incorrect use of inheritance. A Deck "is-not-a" Card.
There are several good references about the equals() method:for example, if you google for Effective Java Joshua Bloch Methods inherited from Object, you might find a sample chapter from the 1st edition, which has lots about the equals() method it. you might find it here. Angelika Langer's website. That actually appears on the Google search I told you about above Odersky Spoon and Venners: you will find a link to their work on our FAQ. Unsynchronized means that multiple threads can gain access to its methods simultaneously. Look in the documentation for ArrayList and the Java™ tutorials for more details.
No, an array list doesn't use a hash code as a routine.
Jon
OCPJP 6, OCE JEE 6 JSP and Servlet Developer
Manjula Weerasinghe wrote:"Deck" is-not-a "Card" as Ritchie has pointed out. So it is not a good design to extend "Card" class for creating "Deck" class. We use extending of classes for representing "IS-A" relationship between two classes.
Relationship between "Deck" and "Card" is, "Deck" has-a (list of)"Card".
That means, "Deck" class has a reference to list of instances of "Card" class.
In your "Deck" class, you have already implemented that relationship using
As I see, "extends Card" part in your existing class is also not required for any functionality of your current code. No harm will be done if you removed that part. But I didn't read all of your code, there may be few other changes also needs to do if you remove "extends Card" part.
Jon
Thank you, you are right, however the implication that I would have to factor out the code currently within the Deck class within the main() method (and will eventually be moved to some calling program when I get to the UI design stage) seems like spaghetti to me, what is your advice?
Stephan van Hulst wrote:I didn't see this thread before I answered you in your other thread here: https://coderanch.com/t/535373/java/java/cannot-read-Collection-custom-class#2428780
As has been proposed earlier in this thread, you should study the resources to find out more about the working of equals() and hashCode().
Thank you, you are right, however the implication that I would have to factor out the code currently within the Deck class within the main() method (and will eventually be moved to some calling program when I get to the UI design stage) seems like spaghetti to me, what is your advice?
What exactly strikes you as spaghetti? It seems like a perfectly reasonable implication.
Jon
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |