views:

176

answers:

8

Introduction:

I'm working on API which provides access to Picasa, Flickr and some other image services.

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

My API allows not only read albums but it also allows to create new albums. In general case in order to create new album API user should user factory method which creates album and then call method WebGallery#addAlbum (newAlbum).

But Flickr doesn't allow to create empty albums, it requires at least one predefined photo in any new album (to make nice album preview probably). In Flickr terms this first photo is called Primary Photo. So in order to create album for Flickr user should use factory method, then add an image to the new album, and then call WebGallery#addAlbum (newAlbum).

Problem:

At the moment WebAlbum class has 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 ();
}

Suggest me better (i.e. shorter) name which has the same meaning.

+2  A: 

public boolean needsDefault;

or, more descriptive

public boolean needsDefaultImg;

EDIT Another question you should ask yourself is if this property even should be exposed. If you want to make the experience of managing albums consistent on all backends, then maybe your library could provide default images where required. A logo for your app, maybe. Users are unlikely to have empty albums for very long anyway.

Segfault
+10  A: 

boolean isEmptyAlbumAllowed

RenderIn
+1  A: 

I would use something like allowsEmptyAlbum or emptyAlbumPermitted

That being said, adding an extra method means that the user of the class needs to know that this could even be an issue and remember to make the check before adding the album. This could be an issue because most developers "want to get things done fast" and would not know about the differences between services.

Even adding a note in the documentation is not enough because many folks calling "addAlbum" would never read the documentation of the method since it seems straightforward (see my research for details).

Ideally, you would either be able to create different factories for each service (and provide the information there), or, if you have to use a single API, find a way of gracefully failing or maybe adding a placeholder image.

Uri
A: 

The short answer to your question:

boolean isDefaultPhotoRequired;

The longer answer: the default photo requirement isn't shared by all WebAlbums, so it's a perfect candidate for using inheritance. Move that behavior to a Flickr specific subclass. You could do something like add the creation of that defaultImage to a Flickr.init().

Jay Jackson
+1  A: 

I would go with

public boolean requiresDefaultImage;

or

public boolean requiresAlbumImage;
Joshua
A: 
   public boolean requiresInitialPhoto ();

   public boolean doesOnePhotoExist ();

   public boolean needsOnePhoto ();
amelvin
A: 

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

Pawel Pabich
A: 

I think you can make it even shorter by removing the redundant Album portion.

public boolean canBeEmpty();
ChaosPandion