If collection of business objects inherits from Collection <T>, when does it not extend it?
I have a collection of business objects (representing data from a database) that inherits from Collection and has a static method that calls the stored proc and then populates its properties with the returned data.
My question is: is it wrong to inherit from Collection since it really does not extend the class? or would it be better not to inherit anything, but instead to save a private variable of type Collection?
It is difficult to answer this without seeing much more details about what you are trying to do. However, I would usually not inherit from Collection, as it actually does not provide enough virtual methods to override. This may change the behavior of your class a little more complicated in the future.
The problem with inheritance is that if you use it, you will depend on the behavior of the Collection base class forever or face complex refactoring. For example, you might want to add filtering, searching, and sorting operations, after which you will need to switch to “List from collection”. You might also want to bind data where you need a BindingList instead of a collection.
ICollection IList <T> . , . , .
, , , - , , , , , .
PS: IList <T> , true IsReadOnly, NotSupportedException , .