문제

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:

public interface Gallery {

    int getNumberOfImages();

    //...
}

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.

다른 팁

I would rule out countImages () too, for the same reason.

Other than that, if there is a more or less consistent naming convention in the codebase Gallery belongs to, I would recommend adhering to it. In absence of a clear project convention, I personally would lean towards size().

계정을 변경하는 이유와는 별도로 수행하는 방법은 PowerShell을 사용하는 것입니다.건강 경고로 제안 된대로 CA를 변경하려고하면 DITRIBUTED 캐시 서비스에서는 지원되지 않는다는 오류가 발생합니다.

The problem with size() is that it's not necessarily clear whether you're returning the number of elements (images in this case) or the size in bytes/kilobytes/megabytes of the collection. For the same reason, I tend to prefer getImageDimensions() to getImageSize(). In your case, I like countImages() because it's clear and concise, but it doesn't follow naming conventions if for example, there are methods like getImage(int). Therefore, I will have to go with int getImagesCount() or better, int getNumberOfImages() or int getNumImages()

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top