Reputation: 7512
I am trying to use the repository pattern in an instance of storing pictures.
What I do is save the actual pics in a directory on disk but save data about the pics and what pics go with what object in a database. I was wondering if I should use 2 interfaces for the storage, like IStorePicRepo
and IStorePicDataRepo
or have 1 interface and implement it in 1 class. Sounds to me like it should NOT be implemented by the same class since we are dealing with 2 different storage mechanisms.
Any thoughts?
Upvotes: 2
Views: 397
Reputation: 1361
There is no silver bullet here.
But I probably will end up with the following design:
IBinaryDataService: For general saving of data as binary format. The objects to be saved must have a method to help write it into an OutputStream. There ought to be a convinent method to load it into the original Object too.
IDataIndexService: For index of data attributes/tags, to help in searching as well. Correspond closely to the data of pic you described.
IPicRepo: Only interface exposed to the client. Clients should use this, and never know about the above two services.
FileSystemBinaryDataServiceImpl: Implementation of the IBinaryDataService above.
DbDataIndexServiceImpl: Implementation of the IDataIndexService above.
PicRepoImpl: Implementation of the IPicRepo above. Use spring to inject FileSystemBinaryDataServiceImpl and DbDataIndexServiceImpl as dependencies.
Additional extensions if you wish:
IPersistentModel: Representation of an object that can be persisted. Has methods write(OutputStream), read(inputStream), and getAttributes():Map
PicModel: Implementation of IPersistentModel above.
PS. This is just a general high level overview.
Upvotes: 2
Reputation: 46496
I don't know much about the Repository pattern, but I wouldn't abbreviate Repository as Repo in my identifier name. Abbrs. confuse me.
Upvotes: 1