Movie repository for storing movies based on country The domain model of my application revolves around movies.

Use case:

We have a movie for which only one title (in one country) is known and we want to know titles of this movie in other countries. To get that information, we call external movie repositories.

The Movie class has a map of titles in countries. It also has a list of external IDs. For example, we might know that IMDB's ID for the movie Breakfast at Tiffany's is tt0054698.

class Movie {

    private Map&lt;Country, String&gt; titles;
    private Year yearOfRelease;
    private Map&lt;ExternalMovieRepository, String&gt; externalIds;

    public Map&lt;Country, String&gt; titles() {
        return titles;
    }

    public Year yearOfRelease() {
        return yearOfRelease;
    }

    public Map&lt;ExternalMovieRepository, String&gt; externalIds() {
        return externalIds;
    }

}


The ExternalMovieRepository enum is used as a key to which external ID value is mapped.

enum ExternalMovieRepository {

    IMDB, ROTTEN_TOMATOES;

}


The classes representing the external movie repositories will be able to find additional information only for Movie instances carrying some information the repository requires.

For example, RottenTomatoesMovieRepository requires the Movie instance either to have a US movie title (&lt;Country, String&gt; map entry) or the Rotten Tomatoes' external ID in its externalIds map.

Here is a draft for an interface that could represent the external repositories:

/**
 * Finds movie title for other countries using information from Movie.
 *
 */
interface MovieTitleFinder {

    boolean accepts( Movie m );      

    Map&lt;Country, String&gt; findTitles( Movie m );

}


An implementation could look like this:

class RottenTomatoesTitleFinder implements MovieTitleFinder {

    private final String US_ISO = "us";

    private CountryRepository countryRepository;

    RottenTomatoesTitleFinder( CountryRepository countryRepository ) {
        this.countryRepository = countryRepository;
    }

    @Override
    public boolean accepts( Movie m ) {
        return ( getUSTitle( m ) != null || getRTId( m ) != null );
    }

    @Override
    public Map&lt;Country, String&gt; findTitles( Movie m ) {
        String rtId = getRTId( m );
        if ( rtId != null ) {
            return findByRTid( rtId );
        }
        String usTitle = getUSTitle( m );
        if ( usTitle != null ) {
            return findByUSTitle( usTitle );
        }
        return Collections.emptyMap();
    }    

    private String getUSTitle( Movie m ) {
        Country us = countryRepository.findByIso( US_ISO );
        return ( m.titles().get( us ) );
    }

    private String getRTId( Movie m ) {
        return ( m.externalIds().get( ExternalMovieRepository.ROTTEN_TOMATOES ) );
    }

    private Map&lt;Country, String&gt; findByUSTitle( String usTitle ) {
        // call some collaborating object
    }

    private Map&lt;Country, String&gt; findByRTid( String rtId ) {
        // call some collaborating object
    }

}


Could this design be improved?
One thing - this design is based on a false premise - that there is only ever a single title within a given country. See for example this movie which has 3 USA titles (albeit only one, final, official title). This can be fixed by changing the Country key of the hash map to a TitleType (which will often be just a country).

Another problem is that Movie isn't really an object - it doesn't implement any member functions. In fact, your RottenTomatoesTitleFinder works by directly manipulating Movie properties rather than calling Movie member functions. This is a violation of basic OO principles.