Previous: Live How to Write Software
I just published an introductory article on persistence approach used in How to Write Software. Welcome read it to get an idea on how persistence works here.
How persistence actually works?
On new message creation, UI passes request for new message creation to MessageRepository, giving it MessageSource it uses to create Message from. MessageRepository creates new Message and gives it MessageSource and StateSource. Message asks StateSource for its state and gives it MessageSource. StateSource creates MessageState, records it into db, and returns it to Message.
Another way Message can be created is from persistent state. When asked for a list of messages it asks MessagePersistence for list of message states. It then creates new Messages giving them state returned by MessagePersistence.
Currently code has no StateSource and its role served by MessagePersistence. This is an opportunity to refactor!