The visitor pattern
A start-up company decided to create a music/song library application using Salesforce public sites and communities. Users can browse through thousands of songs, add them to the cart, and purchase them. There are many types of music genres available on websites, such as pop, rock, electronic, and so on. Prices are based on music genres; thus, during a checkout, the development team needs to maintain a list of different songs sold by genres and calculate the price accordingly. For the sake of simplicity, we will consider only three types of music in our example.
Developers decided that all the songs will share some common properties, such as a title and album name, and thus it makes sense to use inheritance. They developed the following abstract class that must be extended by all types of song/music:
public abstract class Music { protected String title; protected String album; public abstract String getMusicDetail(); } ...