Back to Book

03 - Modularity, Objects, and State

3.0 - Introduction

Recap

Modular System - System divided "naturally" into coherent parts that can be separately developed and maintained.

Design Strategies

The goal of each design strategy is to minimize the amount of time and effort it takes to modify the program.

Object-Based

Stream-Processing

3.1 - Assignment and Local State

What is Assignment?

A variable used to directly map to a value. A variable and its value were interchangeable.

    x <---> 4

For this reason, we could safely substitute every instance of our variable (x) with the value (4) it was mapped to.

    x + 7

is identical to

    4 + 7

When we add assignment, a variable is no longer interchangeable with it's value. A variable now maps to a place.

                -----------
    x -------> | somewhere |
                -----------

In this location, we store our value.

                  -------
                 |   4   |
                  -------

Once again, we still have:

    x + 7
    // becomes
    4 + 7 

Crucially though, we can change the value in the location at any time without our variable knowing.

                  -------
                 |   5   |
                  -------

And now, even though we have the same expression of x + 7, we get a completely different answer.

    x + 7
    // becomes
    5 + 7 // <- This is a completely different expression. x became 5 instead of 4.

Because the value at a location can change at any time, we must begin to start thinking about time. Before the change, x gets subsituted with 4, after with 5.

3.2 - The Environment Model of Evaluation

This section is sort of intuitive to me so I didn't take too many notes.

1 Environment. 3 Frames (A,B,C). 5 Bindings (x,y,z). 2 Shadowed Bindings (x,y).

3.3 - Modeling with Mutable Data

Just by looking at the structure of this section, we can assume that mutable list structure is used to represent both queues and tables.

We can also assume that queues and tables are used as primitives when creating a simulator for digital circuits.

Lastly, we are likely to encounter some_ information regarding how multiple objects can be composed together to mutate each other's state.

Layout of the Section

The layout of the section

Data Abstraction Recap

Let's look again at what data abstraction is:

Shows what a data abstraction is.

We represent a real world concept as something (denoted in picture as a "cloud of nothingness"). This cloud is created via a constructor. Now, anytime we want to work with the real-world concept, we just create a new cloud using our constructor.

To get information out of the cloud, we define selectors.

There is one thing missing however, the ability to modify a pre-existing cloud. To enable this, we define mutators. A mutator just lets us change something about our cloud, more specifically, it lets us modify the internal state of the cloud.

The addition of mutators to a data abstraction.

3.3.1 Mutable List Structure

3.3.2 Representing Queues

3.3.3 Representing Tables

3.3.4 A Simulator for Digital Circuits

3.3.5 Propagation of Constraints