Checkout
Order
Customer
Wallet
The train wreck
1order.getCustomer().getWallet().deduct(amt); // reaching through strangers
State
knows aboutOrder only (so far)
Only talk to your immediate friends. A method should call methods on itself, its parameters, objects it creates, and its direct fields — not reach through a chain of strangers.
1order.getCustomer().getWallet().deduct(amt); // reaching through strangers
Three lifelines hang off Checkout. Checkout should only know its immediate friend Order — yet watch how far this one line of code actually reaches.