All challenges
Code AnalysisIntermediate 60s

Strategy vs state selection

class Checkout: def __init__(self): self.state = 'NEW' def pay(self): if self.state == 'NEW': ... self.state = 'PAID' elif self.state == 'PAID': raise Error('already paid') elif self.state == 'SHIPPED': raise Error('too late') # behavior depends on an internal mode with transitions The object's behavior changes as it moves through defined transitions. Which pattern best models this?

Think you can answer under pressure?

Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.

Play this in a 3-minute battle