1public class Card { 2 3 private int suit; 4 private int face; 5 6 public Card() {} 7 8 /** 9 * Constructs a card object with specified suit and face10 * @param suit -- Suit of card (int)11 * @param face -- Face of card (int)12 */13 14 public Card(int suit, int face) {15 this.suit = suit;16 this.face = face;17 }18 19 public int getSuit() {20 return this.suit;21 }22 public int getFace() {23 return this.face;24 }25 public String toString() {26 String output = "";27 //add switch case that sets output to the face of the card28 switch(this.getFace()) {29 case 1:30 output = "Ace";31 break; 32 case 11:33 output = "Jack";34 break;35 case 12:36 output = "Queen";37 break;38 case 13:39 output = "King";40 break;41 default:42 output = Integer.toString(this.getFace());43 }44 //add another switch case that adds " of " and the suit of the card45 switch(this.getSuit()){46 case 1:47 output += " of Spades";48 break;49 case 2:50 output += " of Hearts";51 break;52 case 3:53 output += " of Diamonds";54 break;55 case 4:56 output += " of Clubs";57 break;58 }5960 return output;61 }62}
This class does not have any documentation.
Consider adding a documentation comment to explain its use.
While it may seem like the functionality of a class is perfectly obvious, any consumers of your API may not be able to pick up on certain details.
Bad Practice
Consider a case where the class given below can be instantiated and provides certain functionalities within each instance in a thread-safe manner, perhaps it is a rest API client.
If there is no documentation comment on the class, it is not immediately obvious that the class is thread safe. Thus, multiple instances of the class may be created to perform operations concurrently, using up both memory as well as OS resources like sockets. If it were known from the beginning that the class were thread safe, the user would not need to create unnecessary extra instances of SomeClass
.
class SomeClass {
// ...
}
Recommended
Make sure to add useful information regarding the usage or implementation of a particular declaration, so that anything about it which can't be understood from the name or some other cue is correctly conveyed.
/**
* Instances of this class are used to perform xyz action.
*
* This class is thread safe and the same instance can be used over multiple threads.
*/
class SomeClass {
// ...
}
Exceptions
This issue will not be reported for model entity classes. If there is any non-obvious behavior associated with a particular class however, do consider documenting it.