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 ...

Get Apex Design Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.