Skip to main content

Linking Classes

Our next task is to add a Category property that indicates what sort of a movie we have, such as “Drama” or “Action”. We could simply add a %StringOpens in a new tab property to Film to store this information, but that would lead to the same value being stored over and over again. If we ever wanted to change one of these values—perhaps replacing “Action” with “Action/Adventure”—we would need to find and change every occurrence.

generated description: linkingclasses1a.gif

An alternative strategy is to store a list of categories in a separate class and then have Film objects refer to the appropriate FilmCategory object, like this.

generated description: linkingclasses1b.gif

FeedbackOpens in a new tab