Listing 1
void cohesion()
{
// We only need one supplier with the best quote.
Atom supplier1 = new Atom();
Atom supplier2 = new Atom();
Atom supplier3 = new Atom();
// Get quotes from each supplier here (not listed).
// After getting quotes from each supplier, we need to make sure that they
// can commit with the appropriate resources.
supplier1.prepare(); // If no exception, they can fully commit.
supplier2.prepare(); // ditto
supplier3.prepare(); // ditto
// Do business logic here to determine which supplier should be used.
// Let's assume that supplier 2 wins the contract.
//
// The cohesion must be completed by letting each supplier know their
// individual outcome.
supplier1.cancel();
supplier2.confirm();
supplier3.cancel();
}