The name field could be
final
. Making a variable final relieves the programmer of excess mental juggling - he/she doesn't have to scan through the code to see if the variable has changed. (From @nerdytenor's answers. @nerdytenor's answers.)You should check the argument in the constructor. Does it make sense to create a
Person
object with a name which isnull
or an empty String? If not, check it and throw aNullPointerException
or anIllegalArgumentException
. (Effective Java, Second Edition, Item 38: Check parameters for validity)A note about the specification:
Flag arguments are ugly. Passing a boolean into a function is a truly terrible practice. It immediately complicates the signature of the method, loudly proclaiming that this function does more than one thing. It does one thing if the flag is true and another if the flag is false!
Source: Clean Code by Robert C. Martin, Chapter 3: Functions.
This should be two methods: toString()
and toFullString()
, for example, without any parameter.
The name field could be
final
. Making a variable final relieves the programmer of excess mental juggling - he/she doesn't have to scan through the code to see if the variable has changed. (From @nerdytenor's answers.)You should check the argument in the constructor. Does it make sense to create a
Person
object with a name which isnull
or an empty String? If not, check it and throw aNullPointerException
or anIllegalArgumentException
. (Effective Java, Second Edition, Item 38: Check parameters for validity)A note about the specification:
Flag arguments are ugly. Passing a boolean into a function is a truly terrible practice. It immediately complicates the signature of the method, loudly proclaiming that this function does more than one thing. It does one thing if the flag is true and another if the flag is false!
Source: Clean Code by Robert C. Martin, Chapter 3: Functions.
This should be two methods: toString()
and toFullString()
, for example, without any parameter.
The name field could be
final
. Making a variable final relieves the programmer of excess mental juggling - he/she doesn't have to scan through the code to see if the variable has changed. (From @nerdytenor's answers.)You should check the argument in the constructor. Does it make sense to create a
Person
object with a name which isnull
or an empty String? If not, check it and throw aNullPointerException
or anIllegalArgumentException
. (Effective Java, Second Edition, Item 38: Check parameters for validity)A note about the specification:
Flag arguments are ugly. Passing a boolean into a function is a truly terrible practice. It immediately complicates the signature of the method, loudly proclaiming that this function does more than one thing. It does one thing if the flag is true and another if the flag is false!
Source: Clean Code by Robert C. Martin, Chapter 3: Functions.
This should be two methods: toString()
and toFullString()
, for example, without any parameter.
The name field could be
final
. Making a variable final relieves the programmer of excess mental juggling - he/she doesn't have to scan through the code to see if the variable has changed. (From @nerdytenor's answers.)You should check the argument in the constructor. Does it make sense to create a
Person
object with a name which isnull
or an empty String? If not, check it and throw aNullPointerException
or anIllegalArgumentException
. (Effective Java, Second Edition, Item 38: Check parameters for validity)A note about the specification:
Flag arguments are ugly. Passing a boolean into a function is a truly terrible practice. It immediately complicates the signature of the method, loudly proclaiming that this function does more than one thing. It does one thing if the flag is true and another if the flag is false!
Source: Clean Code by Robert C. Martin, Chapter 3: Functions.
This should be two methods: toString()
and toFullString()
, for example, without any parameter.