self document save(document document("a_file txt"shortcut keyboardshortcut(save_command savecommand(documentshortcut command save_command here we have something that looks like the first command patternbut bit more idiomatic as you can seemaking the invoker call callable instead of command object with an execute method has not restricted us in any way in factit' given us more flexibility we can link to functions directly when that worksyet we can build complete callable command object when the situation calls for it the command pattern is often extended to support undoable commands for examplea text program may wrap each insertion in separate command with not only an execute methodbut also an undo method that will delete that insertion graphics program may wrap each drawing action (rectanglelinefreehand pixelsand so onin command that has an undo method that resets the pixels to their original state in such casesthe decoupling of the command pattern is much more obviously usefulbecause each action has to maintain enough of its state to undo that action at later date the abstract factory pattern the abstract factory pattern is normally used when we have multiple possible implementations of system that depend on some configuration or platform issue the calling code requests an object from the abstract factorynot knowing exactly what class of object will be returned the underlying implementation returned may depend on variety of factorssuch as current localeoperating systemor local configuration common examples of the abstract factory pattern include code for operating-system independent toolkitsdatabase backendsand country-specific formatters or calculators an operating-system-independent gui toolkit might use an abstract factory pattern that returns set of winform widgets under windowscocoa widgets under macgtk widgets under gnomeand qt widgets under kde django provides an abstract factory that returns set of object relational classes for interacting with specific database backend (mysqlpostgresqlsqliteand othersdepending on configuration setting for the current site if the application needs to be deployed in multiple placeseach one can use different database backend by changing only one configuration variable different countries have different systems for calculating taxessubtotalsand totals on retail merchandisean abstract factory can return particular tax calculation object