Assignment 5: Abstracting over Data Definitions
Goals: Practice designing abstract classes.
You should submit one .java file containing the solution to this problem.
Be sure to properly test your code and write purpose statements for your methods. A lack of tests and documentation will result in a lower grade! Remember that testing requires you to make some examples of data in an examples class.
Premise
In this problem, your data will represent different kinds of media. Each piece of media has a title and list of available languages for captions. Different kinds of media can also contain additional information as shown in the supplied Media.java file.
Note: none of the methods are currently properly implemented. As given in the file, they are all stubs that currently return a dummy value, so the code will compile but not yet work.
Warmup
Download the file and work out the following problems:
Make at least two examples of data for each of the three classes.
Design the isReallyOld method for each class. TV and YouTube are fairly modern formats, but movies that came out before 1930 are considered really old.
Design the method isCaptionAvailable for each class, which determines if a given language is available for captions.
Design the method format which produces a String showing the proper way to display the piece of media in text. Movies are formatted by the title followed by the year in parentheses, such as "The Favourite (2018)". TV episodes are formatted by the show’s title followed by the season and episode number, separated by a period, followed by a dash and then the episode title, such as "Mad Men 1.1 - Smoke Gets In Your Eyes". YouTube videos are formatted by the video’s title followed by the word by followed by the channel name, such as "Threw It On The Ground by thelonelyisland".
Then...
Using Abstract Classes
Change IMedia from an interface to an abstract class, AMedia. Declare all of the methods abstract.
While we sometimes desire both an interface and abstract class, as seen in class, in this case, there is no need for both.
Change all of the concrete classes from implementing an interface to extending the abstract class.
Look at the code and identify all places where the code repeats, providing the opportunity for abstraction.
Lift the common fields to AMedia.
Make sure you include a constructor in the abstract class, and change the constructors in the concrete classes accordingly. Run the program and make sure all test cases work as before.
For each method that is defined in all three classes decide which category it belongs to:
The method bodies in the different classes are all different, and so the method remains abstract in the abstract class.
The method bodies are the same in all classes and it can be implemented concretely in the abstract class.
The method bodies are the same for two of the classes, but is different in one class. Therefore, you can define the common body in the abstract class and override it in only one concrete class.
Once you’ve finished this procedure, be sure all of your tests still pass.