Skip to main content
Code Review

Return to Answer

replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link
  1. 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.)

  2. You should check the argument in the constructor. Does it make sense to create a Person object with a name which is null or an empty String? If not, check it and throw a NullPointerException or an IllegalArgumentException. (Effective Java, Second Edition, Item 38: Check parameters for validity)

  3. 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.

  1. 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.)

  2. You should check the argument in the constructor. Does it make sense to create a Person object with a name which is null or an empty String? If not, check it and throw a NullPointerException or an IllegalArgumentException. (Effective Java, Second Edition, Item 38: Check parameters for validity)

  3. 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.

  1. 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.)

  2. You should check the argument in the constructor. Does it make sense to create a Person object with a name which is null or an empty String? If not, check it and throw a NullPointerException or an IllegalArgumentException. (Effective Java, Second Edition, Item 38: Check parameters for validity)

  3. 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.

Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157
  1. 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.)

  2. You should check the argument in the constructor. Does it make sense to create a Person object with a name which is null or an empty String? If not, check it and throw a NullPointerException or an IllegalArgumentException. (Effective Java, Second Edition, Item 38: Check parameters for validity)

  3. 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.

lang-java

AltStyle によって変換されたページ (->オリジナル) /