Example #1
0
 /**
  * Creates a standard arrangement for the vending machine. All the
  * components are created and interconnected. The hardware is initially
  * empty. The product kind names and costs are initialized to " "
  * and 1 respectively.
  *
  * @param coinKinds
  *            The values (in cents) of each kind of coin. The order of the
  *            kinds is maintained. One coin rack is produced for each kind.
  *            Each kind must have a unique, positive value.
  * @param selectionButtonCount
  *            The number of selection buttons on the machine. Must be
  *            positive.
  * @param coinRackCapacity
  *            The maximum capacity of each coin rack in the machine. Must be
  *            positive.
  * @param productRackCapacity
  *            The maximum capacity of each product rack in the machine. Must
  *            be positive.
  * @param receptacleCapacity
  *            The maximum capacity of the coin receptacle, storage bin, and
  *            delivery chute. Must be positive.
  * @throws IllegalArgumentException
  *             If any of the arguments is null, or the size of productCosts
  *             and productNames differ.
  */
 public VendingMachine(Cents[] coinKinds, int selectionButtonCount, int coinRackCapacity, int productRackCapacity, int receptacleCapacity)
 {
     this.hardwareFacade      = new HardwareFacade(coinKinds, selectionButtonCount, coinRackCapacity, productRackCapacity, receptacleCapacity);
     this.communicationFacade = new CommunicationFacade(this.Hardware);
     this.paymentFacade       = new PaymentFacade(this.Hardware, coinKinds.ToList());
     this.productFacade       = new ProductFacade(this.Hardware);
     this.businessRule        = new BusinessRule(communicationFacade, paymentFacade, productFacade);
 }
 //=====This Business Rules manage and control the three facades based on the hardwares
 public BusinessRule(CommunicationFacade communicationFacade, PaymentFacade paymentFacade, ProductFacade productFacade)
 {
     this.communicationFacade              = communicationFacade;
     this.paymentFacade                    = paymentFacade;
     this.productFacade                    = productFacade;
     communicationFacade.buttonPressEvent += buttonPressed;
     productFacade.productsAddedEvent     += productsAdded;
 }