You are here

IRAContainer.java

15 January, 2016 - 09:02
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/402b20ad-c01f-45f1-9743-05eadb1f710e@37.6
    package rac; 

import listFW.*; /** * Defines the interface for a restricted access container. */ public interface IRAContainer {     /**     * Empty the container.     *  NOTE: This implies a state change.     *  This behavior can be achieved by repeatedly removing elements from this IRAContainer.     *  It is specified here as a convenience to the client.     */ public void clear(); /**     *  Return TRUE if the container is empty; otherwise, return     *  FALSE.     */ public boolean isEmpty(); /**     *  Return TRUE if the container is full; otherwise, return     *  FALSE.     */ public boolean isFull(); /**     *  Return an immutable list of all elements in the container.     *  @param fact for manufacturing an IList.     */ public IList elements(IListFactory fact); /**     *  Remove the next item from the container and return it.     *  NOTE: This implies a state change.     *  @throw an Exception if this IRAContainer is empty.     */ public Object get(); /**     *  Add an item to the container.     *  NOTE: This implies a state change.     *  @param input the Object to be added to this IRAContainer.     *  @throw an Exception if this IRAContainer is full.     */ public void put(Object input); /**     *  Return the next element in this IRAContainer withour removing it.     *  @throw an Exception if this IRAContainer is empty.     */ public Object peek(); } 
  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:
    • First in/First out (FIFO) ("Queue")
    • Last in/First out (LIFO) ("Stack")
    • Retrieve by ranking ("Priority Queue")
    • Random retrieval
  4. 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!

The manufacturing of specific restricted access containers with specific insertion strategy will be done by concrete implementations of the following abstract factory interface.