Python task manager from scratch, part 13: Fix a major mistake

The whole point of the last few installments, and the thousands of words (and however much study) accompanying them, has been to separate the domain and persistence layers. Yet I failed to do that.

To persist or load a Task, the repository needed to turn the domain object to or from the form in which that object is being stored. The domain object is a Task and the persistence representation is a string. The conversion and deconversion ("serialization," in this case) absolutely must be handled entirely at the repository level.

Here I got sloppy and used a convenient mechanism for string representation--the str method on Task, which was easy to reach for--as the repository-level serialization logic. In doing so, I broke the interface between the domain and repository layers.

Now, someone maintaining the Task object cannot change that method without its breaking the persistence layer. This is, again, very very bad:

  1. It makes Task harder to maintain.
  2. It forces someone to keep more things in mind as they reason about either Task or TaskRepository.
  3. It defies an important conventional meaning of ("breaks the semantics of") the str method, which should be used for displaying information about Task in a human-readable way.

The time to fix a mistake like this is now.

Here is the current commit in the veery/ repository.


Home page