6. Quiz Questions

6.1. Question 1: Single-valued reference property

Consider the single-valued reference property Committee::chair, which holds a reference to an instance of the class ClubMember. Which of the following JS code fragments represents the preferred implementation of the setter for this property? Select one:

  1. O

    set chair(c) {
      const clubMember_id = (typeof c !==  "object") ? c : c.memberId;
      this._chair = ClubMember.instances[clubMember_id];
    }
  2. O

    set chair(c) {
      const clubMember_id = c.memberId;
      this._chair = ClubMember.instances[clubMember_id];
    }
  3. O

    set chair(c) {
      const clubMember_id = c;
      this._chair = ClubMember.instances[clubMember_id];
    }
  4. O

    set chair(c) {
      this._chair = c;
    }

6.2. Question 2: Implementing the CASCADE deletion policy

Making the assumption that books existentially depend on their publishers, implying a CASCADE deletion policy, which of the following Publisher.destroy methods correctly implements the implied deletion policy? Select one:

  1. O

    Publisher.destroy = function (name) {
      for (const key of Object.keys( Book.instances)) {
        const book = Book.instances[key];
        if (book.publisher.name === name) {
          delete book._publisher;
        }
      }
      delete Publisher.instances[name];
    };
  2. O

    Publisher.destroy = function (name) {
      for (const key of Object.keys( Book.instances)) {
        const book = Book.instances[key];
        if (book.publisher.name === name) {
          delete Book.instances[key];
        }
      }
      delete Publisher.instances[name];
    };
  3. O

    Publisher.destroy = function (name) {
      for (const key of Object.keys( Book.instances)) {
        const book = Book.instances[key];
        if (book.publisher.name === name) {
          book.publisher = undefined;
        }
      }
      delete Publisher.instances[name];
    };

6.3. Question 3: JS class model

Consider the following OO class model:

Which is the correct JS class model for the Committee class derived from the above model? Select one:

  1. O

  2. O

  3. O