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:
- Make a new instance of Catalog ( ex.:
Catalog c = new CatalogImpl(String sName)
).
- Define a fitting subclass of abstract CatalogItemImpl (See also: HowTo..define a CatalogItem)
or implement the interface CatalogItem.
- Add the Catalog to the Shop´s global list of catalogs (
Shop.getTheShop().addCatalog(Catalog c)
).
- 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
// 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);
}
}