Chapter 4 - Object State Flashcards

1
Q

static/compile-time perspective

A

looking at a software system in terms of the software elements declared in the source code and the relations between them

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

dynamic perspective

A
  • looking at a software system in terms of objects - corresponds to the set of all values and references held by the variables in a program at different points in time
  • can be represented by object, state and sequence diagrams
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

object state

A

the particular pieces of information the object represents at a given moment

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

concrete state

A

collection of values stored in the object’s fields

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

abstract state

A

arbitrarily defined subset of the concrete state space

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

state space

A
  • set of all possible states for a variable/object
  • with fields of reference types, the cardinality of the state space increases dramatically
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

stateless objects

A

objects that do not store any values (eg. function objects which have no fields besides constants)

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

state diagrams

A
  • used to represent how objects can transition from one abstract state to another as a reaction to external events (like method calls)
  • represent a dynamic view of a software system
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

TEMPORARY FIELD antipattern

A

information should not be stored in an object unless it uniquely contributes to the intrinsic value represented by the object

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

ways to model absent values

A
  1. optional types
  2. NULL OBJECT design pattern
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Optional types

A
  • to make a value of type T optional for a variable, declare variable to be of type Optional<T></T>
  • to represent absent variable -> Optional.empty()
  • to represent a value that can never be null -> Optional.of(value)
  • to represent a value which can be null -> Optional.ofNullable(value)
  • to get a value wrapped by instance of Optional -> Optional.get()
  • to check if a value is null -> !variable.isPresent()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

NULL OBJECT design pattern

A
  • relies on polymorphism so only applicable to situations where a type hierarchy is possible
  • create a class to represent a NULL object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

default methods

A

methods that have an implementation in the interface which is applicable to instances of all implementing types (don’t need to provide implementation for them in implementing classes but can override them)

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

final keyword

A
  • prevents changing the value of a field after initialization -> can only be assigned value in declaration of variable or in constructor
  • does not make referenced objects immutable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

identity

A
  • refers to fact that we are referring to a particular object, represented by object ID
  • two different objects with same value will still have different IDs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

== operator

A
  • returns true if two operands evaluate to the same VALUE
  • for reference types -> same value means referring to same object ID
17
Q

object equality

A
  • can be programmer defined by overriding equals methods in Object class (default implementation is a == b)
  • need to override hashCode
18
Q

FLYWEIGHT design pattern

A
  • used to ensure uniqueness of objects of a class
  • control creation of flyweight objects by:
    1. private constructor
    2. static flyweight store: keeps a collection of flyweight objects
    3. static access method: returns unique flyweight object that corresponds to some identification key
19
Q

SINGLETON design pattern

A
  • provides a way to ensure there is only one instance of a given class at any point in the execution of the code
  • template:
    1. private constructor
    2. global variable
    3. accessor method called instance()