execute is the shared command method that performs the operation represented by a Command object. A presentation layer can trigger different commands through this stable interface without knowing their implementations. section 7.2.2
A reliable execute interface should:
- Keep the method available on every command class. section 7.2.2
- Use a consistent signature so commands remain substitutable. section 8.4.1
- Accept data explicitly when commands need to act on it. section 8.4.1
Listing 8.5. An abstract base class for the command pattern
from abc import ABC, abstractmethod #1
class Command(ABC): #2
@abstractmethod
def execute(self, data): #3
class CreateBookmarksTableCommand(Command): #4
def execute(self, data=None): #5
...
class AddBookmarkCommand(Command): #6
...
Shows a Command abstract base class and concrete commands sharing an execute(data) contract. section 8.4.1
