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:
- 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)
)
- Make a new instance of StoringStock associated with the Catalog.
( Stock st = new StoringStockImpl(String sName, CatalogImpl ciRef)
)
- Define a fitting subclass of StockItemImpl (See also HowTo..define a StockItem).
- Add the Stock to the Shop´s global list of stocks (
Shop.getTheShop().addStock(Stock st)
).
- 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
// 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);
}
}