Command mode: Encapsulate a request as an object so that you can parameterize the customer with different requests. It supports request queuing, request logging, and unrecoverable operations.
Advantages: Separates the objects that request an operation from those that know how to perform an operation.
# Encoding = UTF-8 ## by Panda # command mode def printinfo (Info): Print Unicode (Info, 'utf-8 '). encode ('gbk') import time # commandclass command (): Cycler = none def _ init _ (self, Cycler): Self. runner ER = runner er def execute (Self): pass # specific command class: copy a mutton string class bakemuttoncommand (command): def sethandsetsoft (self, runner ER): Command. _ init _ (self, runner ER) def execute (Self): Self. aggreger. bakemutton () def tostring (Self): Return 'catalogue string' # command class: Copy chicken wings class bakechickenwingcommand (command): def sethandsetsoft (self, Handler ER): Command. _ init _ (self, runner ER) def execute (Self): Self. aggreger. bakechickenwing () def tostring (Self): Return 'Copy chicken wings '# runner Er: the catalogue's class barbecuer (): def bakechickenwing (Self): printinfo ('Copy chicken wings! ') Def bakemutton (Self): printinfo ('Copy a mutton string! ') # Invoker: Waiter class waiter (): commandlist = [] def setorder (self, command): printinfo (' % s add order: % s' % (time. strftime ('% Y-% m-% d % H: % m: % s', time. localtime (time. time (), command. tostring () self. commandlist. append (command) def cancelorder (self, command): printinfo ('% s cancel order: % s' % (time. strftime ('% Y-% m-% d % H: % m: % s', time. localtime (time. time (), command. tostring () self. commandlist. remove (command) def every Y (Self): printinfo ('\ n notification:') for command in self. commandlist: Command. execute () def run (Self): printinfo ('run mobile phone address records') def clientui (): Boy = barbecuer () bakemuttoncommand1 = bakemuttoncommand (boy) bakemuttoncommand2 = bakemuttoncommand (boy) bakechickenwingcommand1 = bakechickenwingcommand (boy) GIRL = waiter () Girl. setorder (bakemuttoncommand1) Girl. setorder (bakemuttoncommand2) Girl. setorder (bakechickenwingcommand1) Girl. cancelorder (bakemuttoncommand1) Girl. required y () returnif _ name _ = '_ main _': clientui ();
Class Diagram: