Here I have the following bit of code:
private IList<IState> _states = new List<IState>(); private ReadOnlyCollection<IState> _statesViewer; public IList<IState> States { get { return _statesViewer; } }
I find it usually preferable to return the interfaces rather than the concrete classes themselves, but in this case I should not set the States a ReadOnlyCollection property as the return type?
Any user of my library will think that you can do something that you can do with IList , if I install it like this, which means adding elements. This is not true, and I definitely break the contract by revealing it as an IList.
Am I right from this point of view, or is something else missing?
source share