Reputation: 112
I need to create a Point of Sale application.It has two class one is POS
and other is Bill
.
POS
class creates an instance of Bill
Class & Bill
class handles all the logic to calculate the final bill.
There is one requirement that I don't understand
A single instance of the class POS
should initiate bills.
The interface should be Bill bill = pos.createBill()
. Many clients could call pos.createBill()
method simultaneously on the single POS
instance, even from different threads.
Each call to pos.createBill()
should return a new instance of the Bill
class.
An instance of Bill
will be used only in the one thread it was created in.
I don't understand which class should implement thread and how should I call it?
Upvotes: 0
Views: 122
Reputation: 452
Why "Each call to pos.createBill() should return a new instance of the Bill class."???
Just use one Bill object
Bill bill = pos.createBill()
create this in Global location (In Main or in Form class,out side of any method within class) and use "Bill" in your method call. If and only your method taking too much of time to execute one task put those method calling in thread. Use asynchronously (Async) calling.
Upvotes: 0
Reputation: 4539
In Your POS class you should have thread declared as,
Bill bill = new Bill();
synchronized(bill)
{
Thread t = new Thread() { public void run() {
// calls to bill.create bill.
} };
t.start();
t.join();
}
also As suggested above POS should be Singleton.
Upvotes: 1