Suppose we have classes Gallery and Image. There can be many images in one gallery.
Gallery should have some method which returns number of nested images. My suggestions:
int getImagesCount ();
int countImages ();
int imagesCount ();
I saw examples of each of these 3 suggestions in different APIs (of course with another noun or even without it, like method size () in Collections API).
What would you prefer and why? (One of my thoughts against countImages () is that this name can make user think that this method does some complex calculations.)
My suggestion:
I agree, that
countXX()leads to the impression, that calling this method triggers some sort of calculation. So I wouldn’t use it here as well.