SOURCECODE

How to... define a CatalogItem


Description:
CatalogItems are Catalogs(Subcatalogs) or items itself. They are meant to represent a named category of items and to be stored in a Catalog.
(See also: HowTo incorporate a Catalog )
It is often usefull to subclass CatalogItemImpl, but implementing the interface CatalogItem may also be necessary.

ToDo's:
  1. Incorporate a subclass of abstract CatalogItemImpl.
  2. Add needed attributes. Remember that added attributes should characterize all items in the stock which is referenced to the catalog. If you need attributes to characterize single items in the stock, these attributes should be added to the implemented StockItem.
    (See also: HowTo define a StockItem )
  3. Add constructors to set the items name and other attributes.
    (Every constructor must invoke super(name) or super(name,value), therefore a CatalogItem has to have a name)
  4. Implement protected CatalogItemImpl getShallowClone().
    (Note: On the contrary to the name, the method has to return a DEEP instead of a SHALLOW clone of the CatalogItem.
  5. Add other needed methods.


Uses:
CatalogItem  CatalogItemImpl  



SourceCode

// mainly imports
   import data.ooimpl.CatalogItemImpl;

 1
// Main Class
   public class MyCatalogItem extends CatalogItemImpl
   {
    2
   // Attibutes
      int maximumAmount;

    3
   // Constructor
      public MyCatalogItem(String name, Value value)
      {
         super(name,value);
      }

    4
   // Method has to be implemented
      protected CatalogItemImpl getShallowClone()
      {
         return (CatalogItemImpl)
            new MyCatalogItem(this.getName(), this.getValue());
      }

    5
   /////////////////////////////
   // getter and setter methods

      public void setMaximumAmount(int max)
      {
         maximumAmount = max;
      }

      public int getMaximumAmount()
      {
         return maximumAmount;
      }
   }