Implement 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. 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.
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 Shops methods, because very unlovely runtime errors may be the
result.
Used classes:
ToDo:
-
Create a subclass of
Shop. -
Add constructor to create singleton instance of
Shop. You can initialize some data in the constructor, like setting theShop's frame size, but that is also possible in the main class (see below). -
For invoking the
Shop, create a simple class with thepublic static void main (String[] noArgs)method. -
Therein create an instance of the
Shopand initialize its attribute of the singletonShopinstance by thesetTheShop(Shop TutorialShop)method. Furthermore call thestart()method to start theShop. -
The main class is also used to add a
SalesPoint(or even more) to theShophere.
Example Source Code:
Shop class:
// necessary imports import java.awt.Rectangle; import sale.AutoTimer; import sale.CalendarTime; import sale.Shop; import sale.events.TimerEvent; import sale.events.TimerListener; 1 public class ArchitectureShop extends Shop { 2 public ArchitectureShop() { super(); setShopFrameBounds(new Rectangle(0, 0, 640, 480)); CalendarTime calendarTime = new CalendarTime(); calendarTime.setTimeToCount(CalendarTime.SECOND); AutoTimer autoTimer = new AutoTimer(calendarTime, (long) 992); autoTimer.addTimerListener(new TimerListener() { public void onGoneAhead(TimerEvent timerEvent) { System.out.println(timerEvent.getTime()); } public void onTimeSet(TimerEvent timerEvent) { } public void onIntervalSet(TimerEvent timerEvent) { } }); autoTimer.start(); } }
Main class:
// necessary imports import sale.Shop; import application_architecture.ArchitectureSalesPoint; import application_architecture.ArchitectureShop; import display.DisplaySalesPoint; 3 public class Tutorial { public static void main(String[] args) { 4 ArchitectureShop myTutorialShop = new ArchitectureShop(); Shop.setTheShop(myTutorialShop); myTutorialShop.start(); 5 myTutorialShop.addSalesPoint(new ArchitectureSalesPoint("ArchitectureSalesPoint")); myTutorialShop.addSalesPoint(new DisplaySalesPoint("DisplaySalesPoint")); } }
Back to:
Change quit behaviour
Description:
If the Shop is going to be shutted down, it will ask to make it´s state persistant.
Sometimes this feature makes no sense, therefore it can be modified.
Used classes:
Related topics:
ToDo:
-
Open the designated
Shopclass. -
Implement the
public void quit()method to change the quit behaviour.
Example Source Code:
1 public class ArchitectureShop extends Shop { . . . 2 public void quit() { if(Shop.getTheShop().shutdown(false)) { System.exit(0); } } . . . }
Back to:
Overview | Application Architecture: SalesPoint ![]() |
Overview