Question 1:
void transfer(Account accA, Account accB, double amount) {
synch(accA) {
sync(accB) {
...
}
}
}
There is a deadlock issue, e.g Thread1 transfer from accA to accB, and Thread2 transfer from accB to accA. How to fix this bug?
Question 2:
class Trade
OptionTrade extends Trade
BondTrade extends Trade
SwapTrade extends Trade
Pricer
double getPV(OptionTrade trade)
double getPV(BondTrade trade)
double getPV(SwapTrade trade)
Trade trade = ...//you got a trade instance
Pricer pricer = ...//you got a pricer instance
//how to get price value of the trade
if(trade instanceOf OptionTrade) {
pricer.getPV((OptionTrade)trade)
} else if(... instanceOf ...) {
...
} else if (... instanceOf ...){
...
}
He siad, this works, but looks he is not satisfied with this solution. He asked : "Is there a better way to do that?"
I cannot think of another way..., He followed with a question "what's polymorphism?", so maybe the solution should be related to polymorphism.