Suggest me a better name for the API method

Introduction:

I am working on an API that provides access to Picasa, Flickr, and other image services.

I have a WebAlbum class (it provides access to attached photos, albums, if allowed, and some meta information).

My API allows the user not only to read albums, but also to create new albums. In general, an API user must use the factory method to create a new album, which creates the album and then calls the WebGallery#addAlbum (newAlbum) .

But Flickr does not allow you to create empty albums, this requires at least one predefined photo in any new album (possibly to enjoy viewing the album). In Flickr terms, this is the first photo called Primary Photo . Therefore, to create an album for Flickr, the user must use the factory method, then add the image to the new album, and then call WebGallery#addAlbum (newAlbum) .

Problem:

The WebAlbum class currently has this method.

 public interface WebAlbum { ... public boolean requiresPrimaryPhoto (); } 

I can’t leave this name because PrimaryPhoto is just a Flickr term. I can change it to

 public interface WebAlbum { ... //with spaces: requires one added photo to create new album public boolean requiresOneAddedPhotoToCreateNewAlbum (); } 

Please suggest a shorter name with the same meaning.

+4
source share
8 answers

boolean isEmptyAlbumAllowed

+11
source

public boolean needsDefault;

or more descriptive

public boolean needsDefaultImg;

EDIT Another question you should ask yourself is if this property should even be revealed. If you want the album management experience to fit all the backends, perhaps your library could provide default images if necessary. Perhaps a logo for your application. In any case, users are unlikely to have empty albums.

+2
source

I would go with

 public boolean requiresDefaultImage; 

or

 public boolean requiresAlbumImage; 
+2
source

I would use something like allowEmptyAlbum or emptyAlbumPermited

At the same time, adding an additional method means that the user of the class should know that this may be a problem, and do not forget to check before adding the album. This can be a problem because most developers “want to do this quickly” and will not be aware of the differences between the services.

Even adding a note to the documentation is not enough, because many people calling "addAlbum" will never read the documentation for this method, because it seems simple (see details in my research).

Ideally, you could either create different factories for each service (and provide information there), or if you need to use one API, find a way to gracefully crash, or possibly add a placeholder image.

+1
source

I think you can make it even shorter by deleting the extra part of the album.

 public boolean canBeEmpty(); 
+1
source

Short answer to your question:

 boolean isDefaultPhotoRequired; 

Longer answer: the default requirement for photos is not used by all WebAlbums, so it is an ideal candidate for using inheritance. Move this behavior to a separate Flickr class. You could do something like adding the creation of this default to Flickr.init ().

0
source
  public boolean requiresInitialPhoto (); public boolean doesOnePhotoExist (); public boolean needsOnePhoto (); 
0
source

Create the FlickerWebAlbum and PicasaWebAlbum classes. Each of them will represent behavior specific to each provider.

0
source

Source: https://habr.com/ru/post/1302875/


All Articles