COM1204, Summer 1998, Prof. Futrelle

Midterm Exam, Thursday, August 20th

This is a closed-book, closed-notes exam, 65 minutes in length. "PS" refers to our phone system, "OO" to object-oriented.

1. For simplicity, assume we have two phones, each with a connector, and directly connected to one another by a pair of wires. Since wires are such simple objects, it is possible to include a wire object directly into a connector, rather than using a pointer to a wire. That is, instead of

class Connector {
  public:
    static int next_id;

    int id;

    Wire *in;
    Wire *out;

    Connector();
  };

We could have this, without pointers to Wire objects:

class Connector {
  public:
    static int next_id;

    int id;

    Wire in;
    Wire out;

    Connector();
  };

Describe the complications that the second formulation might produce and why the first is a better approach.

2. Write three descriptions of the following line of code from switch.cp:

connectors[i]->out->packet = new Packet(ring, null_string, -1, -1, -1);

The three descriptions should be:

  1. What the array and "->" notations accomplish and what the new operation accomplishes. What is the type of the right- and left-hand sides of the assignment?

  2. What normally would control whether or not this statement was executed as the simulation proceeds? (exact code not required)

  3. How the code represents the object design of the switch.

3. What does Meyer mean by the statement, "Real systems have no top." In your answer, discuss top-down design and the process of refinement (elaboration). Of course you may want to relate this to the phone system design and function.

4. In the PS, no instance of the class Keywords is ever created. How is this class used and how does it contribute to the modularization of the design?

5. If we added pay phones to our system, changes would have to be made in both the phones and the switches. Does this illustrate a design error on our part or not? Explain.

6. In the phone and switch, states are manipulated by altering slot values. What differences in the design would arise if each distinct state were a distinct object? Would internal boolean slots in State objects still be useful? Could parameter names such as "FFTFF" be useful? Could a member function of a State object for testing state identity, e.g.,

be designed to use only pointer identity?