Is it okay to violate the principle that collection properties should be readonly for performance?
Posted
by uriDium
on Stack Overflow
See other posts from Stack Overflow
or by uriDium
Published on 2010-06-01T13:06:03Z
Indexed on
2010/06/01
13:23 UTC
Read the original article
Hit count: 169
I used FxCop to analyze some code I had written. I had exposed a collection via a setter. I understand why this is not good. Changing the backing store when I don't expect it is a very bad idea. Here is my problem though. I retrieve a list of business objects from a Data Access Object. I then need to add that collection to another business class and I was doing it with the setter method. The reason I did this was that it is going to be faster to make an assignment than to insert hundreds of thousands of objects one at a time to the collection again via another addElement method.
Is it okay to have a getter for a collection in some scenarios? I though of rather having a constructor which takes a collection? I thought maybe I could pass the object in to the Dao and let the Dao populate it directly? Are there any other better ideas?
© Stack Overflow or respective owner