Flashcards
Programming Idioms
Cards in this deck (5)
- 13 Advantages of "Immutable Objects"- inherently thread-safe
- simpler to understand and reason about
- safer - 2Definition of "Immutable object"Objects that cannot change their state after creation.
Sometimes the internal state can change. - 3Common error in reasoning why "immutable objects" are avoided. Two reasons why this is not good reasoning.Programmers worry about the cost of creating a new object instead of updating one.
Reason 1: Often, cost of garbage collection is decreased
Reason 2: Code that protects mutable objects from corruption can be avoided - 44 Characteristics of an immutable Java object.- no setters
- all fields private and final
-don't allow sublclasses to override methods (by declaring the class final or using factory methods)
- don't store references to mutable objects - 5Purpose of "defense copying"To avoid that the internal state of an object (often an object that is considered immutable) is changed by the manipulation of a contained object through a reference outside the object.
Information
- Description
- Informatik Flashcards on Programming Idioms, created by jlab on 31/08/2014.
- Created by
- jlab
- Views
- 18
- Rating