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