Software Construction: Object States

Cards to learn object states

Cards to learn object states


Set of flashcards Details

Flashcards 13
Language Deutsch
Category Computer Science
Level University
Created / Updated 01.01.2020 / 10.01.2020
Weblink
https://card2brain.ch/box/20200101_software_construction_object_states
Embed
<iframe src="https://card2brain.ch/box/20200101_software_construction_object_states/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>

Static perspective on a Software System

Dynamic perspective on a Software System

Object State (Definition)

The state of an object refers to:

  • the pieces of information the object represents at a given moment
  • the actions that the object can perform at a given moment

Object State Definitions (3)

State Space: Set of all possible states for an object.

Concrete State: Value(s) stored at a given moment.

Abstract State: Arbitrarily-defined subset of the state space.

State Space Partitioning (Definition)

The software design task of state space partitioning is to define abstract states that correspond to characteristics that will help construct a clean solution.

State Diagrams (Definition)

State diagrams allow us to self-evaluate the impact of design decisions on the complexity of the abstract state space that must be considered when working with an object.

Here the abstract state space would consist of State A & B.

Example state diagram for an instance of deck (with separate initialization and shuffling)

Design Principle for State Space

Minimize the state space of objects to what is absolutely necessary for the object to fulfill its responsibilities.

Unnecessary Stateful Information

Temporary FIeld is anti-pattern (don't do this!)

?? In this example the temporary value aSize is unnecessary, as the same information is in aCards.size ??

Nullability (Definition)

The state or property of being nullable.

I.e. if we don't want a reference to be null, we need to ensure this!

Final Fields & Variables (Definition)

Java final variable: If you make any variable as final, you cannot change the value of final variable (It will be constant). A blank (null) final variable can only be initialized in the constructor!

Java final method: If you make any method as final, you cannot override it. A constructor can never be declared final (because it's never inherited)!

Java final class (object): If you make any class as final, you cannot extend itFinal fields do not make the referenced objects immutable! (i.e. only the reference pointer is immutable, but not the object itself)

Object Identity, Equality, & Uniqueness

The direct object reference is equal to it's pointer, not the object itself! If we want to compare 2 object by class / type we need to use ObjName.getClass()!

Example of object comparison code