Skip to main content
9 events
when toggle format what by license comment
Nov 21, 2016 at 9:19 comment added t3chb0t @FCin I've added one more example about how you could solve the caching by implementing a decorator for the normal repository.
Nov 21, 2016 at 9:17 history edited t3chb0t CC BY-SA 3.0
added 1542 characters in body
Nov 21, 2016 at 8:59 vote accept FCin
Nov 21, 2016 at 8:58 comment added t3chb0t @FCin exactly. The repository shouldn't know anything about creating documents. All it cares about is getting and saving them. The factory knows how to create various documents and you probably have many of them because of the IDocument abstraction. This way you can test each of them separately and make changes to any of them without breaking the other one.
Nov 21, 2016 at 8:56 comment added FCin Thank you for your help. If I understand correctly I should first create document with DocumentFactory and then add it to database via DocumentRepository?
Nov 21, 2016 at 8:52 history edited t3chb0t CC BY-SA 3.0
added 53 characters in body
Nov 21, 2016 at 8:46 comment added t3chb0t @FCin a Manager usually means I don't know how to name it better ;-D and it's usually class that does too much (like this example). A repository stores or privdes access to a data storage - depends on the concrete requirements whereas a factory is responsible for creating things. So actually you need both a DocumentRepository for retrieving documents and for adding them from/to an internal collection or a database and a DocumentFactory for creating documents. Those two concerns need be separated.
Nov 21, 2016 at 8:40 comment added FCin So would it be a good practice to rename it to DocumentRepository and add method Save that would send ActiveDocuments to database? I thought that managers should be responsible for managing (saving, removing, creating, changing) that's why I named it DocumentManager EDIT: Close and Create is because I later want to check if document has unsaved changes and probably other things.
Nov 21, 2016 at 8:31 history answered t3chb0t CC BY-SA 3.0