HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

Movie repository for storing movies based on country

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
moviemoviescountryforrepositorybasedstoring

Problem

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 titles;
    private Year yearOfRelease;
    private Map externalIds;

    public Map titles() {
        return titles;
    }

    public Year yearOfRelease() {
        return yearOfRelease;
    }

    public Map 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 (` 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 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

Solution

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.

Context

StackExchange Code Review Q#14993, answer score: 7

Revisions (0)

No revisions yet.