liveBook · Manning

Design pattern

As explained in Practices of the Python Pro

A design pattern is a reusable solution structure for recurring problems in software design, expressed in terms of objects, components, or their interactions.

A design pattern is a reusable solution structure for recurring software-design problems. Naming patterns gives teams a shared vocabulary for discussing objects, components, and their interactions. section 11.2

Patterns can improve loose coupling and extensibility, but they are tools rather than rules. If a pattern feels forced, a simpler or more idiomatic Python approach may be better. section 11.2 section 11.2.1

Command pattern in Bark

A menu choice triggers an action without directly depending on its implementation: PersistenceLayer classes act as receivers, Command classes hold the required information, Option instances invoke commands, and the client connects everything. section 11.2

Useful starting terms include:

Figure 11.5. The command pattern as used in the Bark application

Use the UML diagram to inspect how receivers, commands, invokers, and the client relate in the command pattern. section 11.2

How Practices of the Python Pro covers it

How deep it goes
Explains the pattern concept, maps one command-pattern example, and introduces UML without surveying implementations in depth.
Examples
Uses Bark’s persistence layer, commands, menu options, client module, and a UML diagram as concrete examples.
What you can do after
Apply it via named patterns to separate requesting code from actions and judge whether a pattern feels appropriate in Python.
How it connects
Connects design patterns with loose coupling, extensibility, UML, factories, command patterns, and adapter patterns.

Also explained in

Compare how 7 books explain design pattern →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practices of the Python Pro. The section links point to the parts of the book it draws on.