For example when you have the class Room
in which every room gets (or atleast should get) a different room number, do you ever allow yourself that you name that variables roomNumber
instead of just room
? Because you already know it's of the Room
class, you could omit room
in roomNumber
, and just leave it number
. For consistency sake I want to either include this information already specified by the class or omit it always.
Class Room {
private int roomNumber;
Room(int roomNumber) {
this.roomNumber = roomNumber;
}
}
or
Class Room {
private int number;
Room(int number) {
this.number = number;
}
}
I am thinking about how it would look if you would room.getRoomNumber() or room.getNumber(); and which would make more sense most of the times.
(Welcome to slowy's philosophical programming class)
getNumber() may sound okay. But how does it look, when the room has ten more attributes? How does it look for someone else? What if you would have a Type Employee with an employeeNumber and a Reservation with a reservationNumber? How does the business talk about it? How would the label of a web-gui be named for this property?
Keep in mind:
1) Most of the time, it's better to name methods and variables in a way, so that it's easier to understand. If you name something, try to name it, so you don't have to comment it. If the variable is longer than your 24" wide screen tft, well, something went horribly wrong hehe. In your case, I would have commented, that getNumber() will return the room number, just to make it perfectly clear. Not necessary otherwise.
2) Consistency: If the business is talking about a room number, name it room number. From the member variables, to methods, to table columns. If possible. It makes everything easier. This includes methods like "readRoomByRoomNumber()" instead of "readRoomByNumber()".
3) Naming of variables: Also declare "Room room = new Room()" and not "Room r = new Room()". So in the end: "room.getRoomNumber" is so much easier to read than "r.getNumber()" ;-)
Hope this helps, regards, slowy