Home Segments Top Top Previous Next

330: Mainline

Suppose that you want to insist that both the Movie class and the Sympony class have a rating method. If both use the same rating method, then you can define it in the Attraction class, enabling its use in all subclasses.

If the two classes use different rating methods, then your good-faith intention to define rating in both the Movie and Symphony subclasses may be derailed, especially if someone else is in charge of those classes. Fortunately, Java provides a mechanism that turns good-faith intentions into ironclad requirements.