Make Defensive Copies

           Parag Shah

 http://www.diycomputerscience.com
Even though Java is a safe language, it is still
possible for programmers to make safe mistakes
     and destroy the invariants of an object
When to not make defensive

When a collaborator is doing an explicit hand-off
 of the object in the constructor
When it is very expensive to make copies
Model objects... eg: Hibernate pojo's

Make defensive copies

  • 1.
    Make Defensive Copies Parag Shah http://www.diycomputerscience.com
  • 2.
    Even though Javais a safe language, it is still possible for programmers to make safe mistakes and destroy the invariants of an object
  • 8.
    When to notmake defensive When a collaborator is doing an explicit hand-off of the object in the constructor When it is very expensive to make copies Model objects... eg: Hibernate pojo's