Rice University - Comp 212 - Intermediate Programming

Spring 2002

Lecture #19 - Restricted Access Containers (RACs) and the Strategy Pattern


Restricted Access Containers

  1. Restrict the users from seeing inside or working on the inside of the container.
  2. Have simple put(data) and get() methods. Note the lack of specification of how the data goes in or comes out of the container.
  3. However, a "policy" must exist that governs how data is added ("put") or removed ("get"). Examples:
    1. First in/last out (FIFO) ("Queue")
    2. Last in/first out (LIFO) ("Stack")
    3. Retrieve by ranking ("Priority Queue")
    4. Random retrieval
  4. The policy is variant behavior --> abstract it.
    1. The behavior of the RAC is independent of exactly what the policy does.
    2. The RAC delegates the actual adding ("put") work to the policy.
    3. The RAC is only dependent on the existence of the policy, not what it does.
    4. The policy is a "strategy" for adding data to the RAC. See the Strategy design pattern.
    5. Strategy pattern vs. State pattern -- so alike, yet so different!