-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.py
More file actions
28 lines (23 loc) · 822 Bytes
/
Copy pathCommand.py
File metadata and controls
28 lines (23 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
###############
# Command
# Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log request, and support undoable operation.
###############
#Command -> declares an interface for executing operation
class Command:
receiver = None
def __init__(self, receiver):
self.receiver = receiver
def execute(self):
pass
#ConcreteCommand -> define a binding between a Receiver object and an action
class ConcreteCommand(Command):
def execute(self):
self.receiver.action()
#Receiver -> know how to perform the operations associated with carrying out a request.
class Receiver:
def action(self):
print('do operation!')
#main
if __name__ == '__main__':
command = ConcreteCommand(Receiver())
command.execute()