titleobject oriented design number titleobjects in python comparing this to the original simplified xml document tells us the parser is working state versus strategy the state pattern looks very similar to the strategy patternindeedthe uml diagrams for the two are identical the implementationtoois identicalwe could even have written our states as first-class functions instead of wrapping them in objectsas was suggested for strategy while the two patterns have identical structuresthey solve completely different problems the strategy pattern is used to choose an algorithm at runtimegenerallyonly one of those algorithms is going to be chosen for particular use case the state patternon the other hand is designed to allow switching between different states dynamicallyas some process evolves in codethe primary difference is that the strategy pattern is not typically aware of other strategy objects in the state patterneither the state or the context needs to know which other states that it can switch to state transition as coroutines the state pattern is the canonical object-oriented solution to state-transition problems howeverthe syntax for this pattern is rather verbose you can get similar effect by constructing your objects as coroutines remember the regular expression log file parser we built in the iterator patternthat was state-transition problem in disguise the main difference between that implementation and one that defines all the objects (or functionsused in the state pattern is that the coroutine solution allows us to encode more of the boilerplate in language constructs there are two implementationsbut neither one is inherently better than the otherbut you may find that coroutines are more readablefor given definition of "readable(you have to understand the syntax of coroutinesfirst!the singleton pattern the singleton pattern is one of the most controversial patternsmany have accused it of being an "anti-pattern" pattern that should be avoidednot promoted in pythonif someone is using the singleton patternthey're almost certainly doing something wrongprobably because they're coming from more restrictive programming language