SOURCECODE

How to... incorporate a Catalog


Description:
An important data structure is the Catalog. It provides all what is needed to store and administrate the Shop´s goods.
It is also easy to display a Catalog´s contents with already implemented FormSheets, the JCatalogTable and the DefaultCatalogItemTED for example.
(See also: HowTo..create a Table and HowTo..define a new TableLayout)
The use of CatalogImpl, the implementation of the interface Catalog is recommended.

ToDo's:
  1. Make a new instance of Catalog ( ex.: Catalog c = new CatalogImpl(String sName) ).
  2. Define a fitting subclass of abstract CatalogItemImpl (See also: HowTo..define a CatalogItem)
    or implement the interface CatalogItem.
  3. Add the Catalog to the Shop´s global list of catalogs ( Shop.getTheShop().addCatalog(Catalog c) ).
  4. Add and remove CatalogItems as you wish
    ( c.add(CatalogItem ci, Databasket db); c.remove(CatalogItem ci, Databasket db) ).

It is possible to administrate a Stock of the real exisiting items, described in the Catalog.
(See also: HowTo..incorporate a CountingStock on a Catalog and HowTo..incorporate a StoringStock on a Catalog )

Uses:
Catalog  CatalogItem  CatalogImpl  CatalogItemImpl  



SourceCode

// mainly imports
   import data.Catalog;
   import data.ooimpl.CatalogImpl;

// 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
      // a new instance of Catalog
         Catalog clothesCatalog = new CatalogImpl("clothesCatalog");

       4
      // adding several items to the new Catalog
      // ClothesCatalogItem is a direct subclass of the abstract CatalogItemImpl
         clothesCatalog.add( new MyCatalogItem( "Hats", new IntegerValue(500) ),
                              (DataBasket) null );
         clothesCatalog.add( new MyCatalogItem( "Trousers", new IntegerValue(2500) ),
                              (DataBasket) null );
         clothesCatalog.add( new MyCatalogItem( "Shoes", new IntegerValue(1000) ),
                              (DataBasket) null );

       3
      // adding the catalog to the shop
         myshop.addCatalog(clothesCatalog);

      }
   }