views:

203

answers:

2

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?

+1  A: 

I don't know much about the Repository pattern, but I wouldn't abbreviate Repository as Repo in my identifier name. Abbrs. confuse me.

Jay Bazuzi
+2  A: 

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.

Kent Lai