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:
- It makes
Taskharder to maintain.
- It forces someone to keep more things in mind as they reason about either
- It defies an important conventional meaning of ("breaks the semantics of") the str method, which should be used for displaying information about
Taskin a human-readable way.
The time to fix a mistake like this is now.