The final part of the TaskDB
class defines three methods, create()
that will create a completely new Task
instance, retrieve()
that will fetch a task from the task
table given a task_id
and return it as a Task
instance, and list()
that will return a list of task_id
s for a given user.
We separated retrieve()
and list()
because retrieving an object complete with all its attributes might be quite expensive and not always needed. For example, if we were to select a list with thousands of tasks, we would likely display them as a page of about twenty tasks each. If we were to retrieve complete information for all those tasks, we might have to wait a while, so we might choose to instantiate only a first page-full of them and fetch the rest on an as-needed basis as the users step through the pages. We will encounter this pattern a few more times in this book.
The create()
method itself simply passes on all parameters to the Task
constructor together...