Reputation: 6562
Let's assume I have a class SuperPower, and that I want to put my super powers in a collection without exposing the implementation.
I try to avoid having collections as instance attributes. Instead I put it in a class to which I can move behavior otherwise left spread out in other classes.
I don't want to call it SuperPowerList, SuperPowerMap or similar, because it exposes the implementation.
I also kind of dislike SuperPowers, because it is too similar to the class it contains.
The same goes to variables of the type, "SuperPowers superPowers".
There must be a better way.
Upvotes: 1
Views: 121
Reputation: 73183
SuperPowerCollection
sounds the best as I can see that in the Framework throughout. Variable naming can be anything you are comfortable with as it is not as important. I prefer superPowers
which is more common with collection classes. To get more creative ideas, please post the question at english stackexchange.
Only if I wont be downvoted:
are some of the fancy names I can think of :)
Upvotes: 2
Reputation: 4137
Use either SuperPowerCollection or SuperPowers.
Both are fine.
I would like to add that I saw a case in code where an implementation
got changed from List to Map, but the name of the variable remained objctsList -
this is quite horrible, so you are correct that a good practice will be to avoid providing implementation details in the variable name as they may change in time.
Upvotes: 1