Bark is a command-line bookmarking application for creating, listing, and deleting bookmarks. Each bookmark stores an ID, title, URL, optional notes, and a date-added timestamp. section 6.2
The application separates presentation, business logic, and persistence. A terminal menu triggers commands, while the database stores bookmark data; each layer knows only enough about its surroundings to perform its job. section 6.3.3 section 11.5.1
The interactive workflow follows a small, repeatable cycle:
- Clear the terminal and print actions such as adding, listing by date or title, deleting, and quitting. section 6.3.3
- Validate the user's choice, gather required bookmark fields, and allow notes to remain optional. section 6.3.3
- Execute the selected command, display its result, wait for Enter, and return to the menu. section 6.3.3
- Initialize the bookmarks table before entering the loop, creating the database file when necessary. section 6.3.3
A menu option connects interface and behavior
An add option pairs the label "Add a bookmark" with an AddBookmarkCommand and a preparation function that collects title, URL, and notes. The menu handles interaction; the command handles the requested operation. section 6.3.3
Listing 6.11. Connecting menu text to business logic commands
class Option:
def __init__(self, name, command, prep_call=None):
self.name = name #1
self.command = command #2
self.prep_call = prep_call #3
def choose(self): #4
data = self.prep_call() if self.prep_call else None #5
message = self.command.execute(data) if data
else self.command.execute() #6
print(message)
def __str__(self): #7
return self.name
Inspect the compact Option class to see how menu labels, input preparation, command execution, and result printing are kept together without placing business logic in the interface. section 6.3.3
