[Cs3] Lab 12

Md. Islam mislam4 at kent.edu
Sun Nov 19 16:02:16 EST 2017


>
> I just have a general question about the observer portion of lab 12.
>
> Instructions:
> Extend your program as follows. In "Coffee Shack", the barista takes the
> customers' order and then prepares their drunks.
> The barista may serve her customers concurrently. Once the drink is ready,
> the customers are notified.
> Specifically, after taking an order, the barista randomly either notifies
> all customers that one of the drinks is ready, the drinks may not
> necessarily be prepared in the FIFO order, or starts taking a new order.
> Code the service of "Coffee Shack" using Observer Design Pattern.
> Customer objects should be registering with Barista object and being
> notified when a drink is ready.
> All customers could be notified at once. Then, each customer should
> determine if it is her drink.
>
> My issue:
> I am not sure how to delay the creation of drinks.
>
> Upon taking an order, should the Barista create the appropriate drink
> object and store it until all customers are notified, or should the
> creation of the drink object be delayed?
>

Upon taking an order, the barista may choose to take another order or
prepare drink (probabilistically). This is why you need a vector/queue of
order. The pseudocode can be:

while(true)
{
    //Take an order or prepare a drink randomly. If there is no order in
the queue, take new order.

    //If barista prepared the drink, notify all the customers immediately
using observer pattern (You can use push or pull method as you wish)
}


>
> Should the Barista have a vector of drinks?
>

> Specifically, I am struggling with these:
> 1) The barista may serve her customers concurrently
>
> 2) Specifically, after taking an order, the barista randomly either
> notifies all customers that one of the drinks is ready, the drinks may not
> necessarily be prepared in the FIFO order, or starts taking a new order.
>
>
No, the Barista should have a vector of Order (Drink+customer Name)
instead. Every time he takes a new order, the order should be added to the
vector. If he choose to prepare a drink, he picks an oder from the vector
(in FIFO order or not. You can implement the ordering as you like).

Please let me know if this is not clear.


> Hopefully I have described my issue with enough detail.
> I appreciate any help you can provide.
>
>
Thanks
Tamim
PhD Candidate,
Kent State University
http://web.cs.kent.edu/~mislam4/ <https://web.cs.kent.edu/~mislam4/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://listmail.cs.kent.edu/pipermail/cs3/attachments/20171119/55885fb9/attachment.html 


More information about the cs3 mailing list