Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Apex Design Patterns

You're reading from   Apex Design Patterns Harness the power of Apex design patterns to build robust and scalable code architectures on the Force.com platform

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher
ISBN-13 9781782173656
Length 256 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Jitendra Zaa Jitendra Zaa
Author Profile Icon Jitendra Zaa
Jitendra Zaa
Anshul Verma Anshul Verma
Author Profile Icon Anshul Verma
Anshul Verma
Arrow right icon
View More author details
Toc

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();  
} 
...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime