I have what amounts to a data object but I would like to be able to restrict access to it by revealing this object under different interfaces ("Readable" & "Writable" for simplicity).
I was planning on having my implementation class implement both interfaces and casting between them internally (for example if I am passed a "Writeable" but want to read it I would cast it to "Readable")
This all seemed ok until I was using a mock object framework to mock the implementation of the Writeable to pass in - my casting internally is not supported by the runtime implementation of the interface (produced by dynamic proxy) - this sort of problem usually in my experience points to a design problem.
So, my question is what sort of design change should I consider?
One possible change would be to forget the "Readable" & "Writable" interfaces and combine them into a "DataObject" interface that allows reading and writing?