Chapter2 - Encapsulation Flashcards

1
Q

PRIMITIVE OBSESSION antipattern

A

tendency to use primitive types to represent other abstractions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

immutable objects

A

their class provides no way to change the internal state of the object after initialization (eg. String)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

2 methods for exposing internal information

A
  1. returning a copy of the object using a copy constructor
  2. using unmodifiable view collections (Collections.unmodifiableList(list)) - returns an unmodifiable wrapper around a list.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

defensive programming

A

when corner cases are checked for everywhere in the code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly