27
The State Pattern
The State pattern is used when you want to have an object represent the state of your application and then switch application states by switching objects. For example, you could have an enclosing class switch between a number of related contained classes and then pass method calls on to the current contained class. Design Patterns suggests that the State pattern switch between internal classes in such a way that the enclosing object appears to change its class. In Python, at least, this is a bit of an exaggeration, but the actual purpose to which the classes are put can change significantly.
Many programmers have experienced creating a class that performs slightly different computations or displays different information ...
Get Python Programming with Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.