Chapter2 - Encapsulation Flashcards
1
Q
PRIMITIVE OBSESSION antipattern
A
tendency to use primitive types to represent other abstractions
2
Q
enum types + 2 methods
A
- class declaration where identifiers are globally available constants
–METHODS–
- ordinal(): gives position (int) of enum constant
- values(): an array of enum type containing all enum constants
3
Q
INNAPROPRIATE INTIMACY antipattern
A
pair of classes that are too tightly coupled - they use a significant number of method and fields of the other
4
Q
immutable objects
A
their class provides no way to change the internal state of the object after initialization (eg. String)
5
Q
2 methods for exposing internal information
A
- returning a copy of the object using a copy constructor
- using unmodifiable view collections (Collections.unmodifiableList(list)) - returns an unmodifiable wrapper around a list.
6
Q
defensive programming
A
when corner cases are checked for everywhere in the code