|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.uci.ics.inf111.dvdvendor.devices.DVDDispenser
public class DVDDispenser
The DVDDispenser class represents a wrapper for a hardware driver
of the device to receive and dispense the DVDs. Because we are not really using
such a device, our class provides methods to simulate the device is receiving
or dispensing DVDs.
The DVDDispenser uses an Observer (or Listener) design
pattern. Objects which implement the DVDDispenserListener
interface may use the attach()
method to register with
the DVDDispenser. When a receive or dispense event occurs, the DVDDispenser
reports the event to its observers using their notify methods.
In this example, we do not support detaching from the DVDDispenser.
Field Summary | |
---|---|
private java.lang.String |
barCode
bar code records the current bar code of the DVD being sensed in the DVDDispenser. |
private java.util.Vector<DVDDispenserListener> |
observers
observers is a Vector of DVDDispenserListeners which will be notified of receiving and dispensing events. |
Constructor Summary | |
---|---|
DVDDispenser()
This simple constructor initializes a blank bar code and an empty set of observers. |
Method Summary | |
---|---|
void |
attach(DVDDispenserListener ddl)
The attach() method registers a DVDDispenserListener to receive all future DVDDispenserEvents. |
void |
blankCode()
The blankCode() method reset the bar code of the DVDDispenser |
void |
dispense(java.lang.String barCode)
dispense() is the method we use to simulate the DVD dispenser is dispensing a product. |
java.lang.String |
getBarCode()
Returns the current bar code being registered by the DVD Dispenser reader. |
private void |
notifyObserver(DVDDispenserEvent event)
notifyObserver() passes the information of the event along to the observer objects as a DVDDispenserEvent, which includes the current bar code in the the DVD dispenser. |
void |
receive(java.lang.String barCode)
receive() is the method we use to simulate the DVD dispenser is receiving a product. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.lang.String barCode
private java.util.Vector<DVDDispenserListener> observers
Constructor Detail |
---|
public DVDDispenser()
Method Detail |
---|
public java.lang.String getBarCode()
public void receive(java.lang.String barCode)
barCode
- The bar code read in this event.public void dispense(java.lang.String barCode)
barCode
- The bar code read in this event.public void blankCode()
private void notifyObserver(DVDDispenserEvent event)
event
- An event containing the event type and the current bar code in the dispenser.public void attach(DVDDispenserListener ddl)
ddl
- The Listener (often the calling object) to be attached.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |