SOURCECODE

How to... incorporate a Shop


Description:
The Shop is the central class of a SalesPoint application. You can run Processes on the Shop itself, you can add SalesPoints where you can run Processes too.
(See also: HowTo..incorporate a SaleProcess, HowTo..run a Process on Shop display, HowTo..incorporate a SalesPoint )
The Shop provides a central MenuSheet, where important actions could be invoked (save, load, quit etc.). You may wish to change this MenuSheet in order to open SalesPoints or to offer additional user interaction.
(See also: HowTo..define a MenuSheet in a Shop, HowTo..alter a Shopīs MenuSheet during runtime )
All sorts of central data should be stored here, like Catalogs, Stocks, Currencys, MoneyBags, UserManagers and other attributes that are of global use.
It is important to make a singleton instance of Shop and declare it with the static Shop.setTheShop() method. If you need the shop instance, call Shop.getTheShop(). Donīt try to use the instance, you can get in your shopīs methods, because very unlovely runtime errors may be the result:
(ex.: Take public Attrib getAttribute() { return Shop.getTheShop().myAttrib; }
instead of public Attrib getAttribute() { return this.myAttrib; } )

ToDo's:
  1. Incorporate a subclass of Shop.
  2. Add constructor to create singleton instance of Shop.
    Some data can be initialized in the constructor but this task can be displaced to the main method easily.
  3. Implement public static void main (String[] noArgs) method to initialize the Shop.
  4. Make singleton instance of Shop.
  5. Initialize the Shop.
    Therefore use setTheShop(Shop shTheShop) method to initialize Shopīs attribute of the singleton Shop instance.
    Furthermore use Shop.getTheShop().start() method to make the Shop running and display the Shopīs frame.
  6. If you want to add SalesPoints from the very first, it will be advantageous to do it now.
    Donīt forget to attach a DataBasket to the SalesPoint.

Finally Catalogs, Stocks and UserManagers may be initialized and added to the Shop.
(See also: HowTo..incorporate a Catalog,
HowTo..incorporate a CountingStock on a Catalog, HowTo..incorporate a StoringStock on a Catalog,
HowTo..use the UserManager )

Uses:
Shop  SalesPoint  SaleProcess  Catalog  Stock  Currency  MoneyBag  UserManager  



SourceCode

// mainly imports
   import sale.Shop;
   import sale.SalesPoint;

   import data.ooimpl.DataBasketImpl;

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

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

       5
      // make the shop starting
         Shop.setTheShop(myshop);
         myshop.start();
         myshop.getShopFrame().setSize(640,480);
         myshop.getShopFrame().validate();

       6
      // add salespoints
         SalesPoint sp = new VideoCounter();
         sp.setSalesPointFrameBounds(new java.awt.Rectangle(200,200,500,400));
         sp.attach(new DataBasketImpl());
         myshop.addSalesPoint(sp);
      }
   }