SOURCECODE

How to... incorporate a StoringStock on a Catalog


Description:
This data structure is meant to store individual representations of entrys in the associated Catalog.
In contrast to the CountingStock it is meant to remember the differences between the StockItems.
The StoringStock could be displayed in the same way as the Catalog itself.
(See also: HowTo..create a Table and HowTo..define a new TableLayout)
Using StoringStockImpl, the implementation of the interface StoringStock, is sufficient in most cases.

ToDo's:
  1. Get the instance of Catalog you want to incorporate a StoringStock on. (See also: HowTo incorporate a Catalog )
    ( ex.: CatalogImpl ciRef = (CatalogImpl) Shop.getTheShop().getCatalog(String sName))
  2. Make a new instance of StoringStock associated with the Catalog.
    ( Stock st = new StoringStockImpl(String sName, CatalogImpl ciRef) )
  3. Define a fitting subclass of StockItemImpl (See also HowTo..define a StockItem).
  4. Add the Stock to the Shop´s global list of stocks ( Shop.getTheShop().addStock(Stock st) ).
  5. Add and remove StockItems as you wish.
    ( st.add(StockItem si, DataBasket db); st.remove(StockItem si, Databasket db) )


Uses:
StoringStock  StoringStockImpl  StockItem  StockItemImpl  Catalog  CatalogImpl  



SourceCode

// mainly imports
   import data.StoringStock;
   import data.ooimpl.StoringStockImpl;
   import data.ooimpl.StockItemImpl;

// Main Class
   public class MyShop extends Shop
   {
   // Constructor
      public MyShop()
      {
         super();
      }

   // Main Method
      public static void main (String[] noArgs)
      {
      // the singleton instance of the shop
         MyShop myshop = new MyShop();

       1
      // getting the catalog
         clothesCatalog = (CatalogImpl) Shop.getTheShop().getCatalog("clothesCatalog");

       2
      // a new instance of StoringStock
         StoringStock clothesStoringStock =
         new StoringStockImpl("clothesStoringStock", (CatalogImpl) clothesCatalog);

       5
      // adding five trousers to the stock
         for (int i=0; i<5; i++)
            clothesStoringStock.add(new StockItemImpl("Shoes"), (DataBasket) null);

       4
      // adding the storingstock to the shop
         myshop.addStock(clothesStoringStock);
      }
   }