title: Different Classes with Similar Methods
body: <p>Let's say I am making scrollable pages with a <code>UICollectionView</code>. The pages are all different and are populated by a pages array like the one below:</p>
  
  <pre><code>let pages = [GreenPage(), YellowPage(), OrangePage(), YellowPage(), GreenPage()]
  </code></pre>
  
  <p>So, to clarify, there would be a page that's green, then followed by yellow, then orange ...</p>
  
  <p>Now, let's say I want to make it so that when one is tapped, it runs a function called <code>tapped()</code> which occurs in each <code>GreenPage()</code>, <code>YellowPage()</code>, and <code>OrangePage()</code>.</p>
  
  <p>Now, the only way I see to do this would be the following: </p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
      if let greenPage = collectionView.cellForItem(at: indexPath) as! GreenPage {
  
          greenPage.tapped()
  
      } else if let yellowPage = collectionView.cellForItem(at: indexPath) as! YellowPage {
  
          yellowPage.tapped()
  
      } else if let orangePage = collectionView.cellForItem(at: indexPath) as! OrangePage {
  
          orangePage.tapped()
  
      }
  }
  </code></pre>
  
  <p>This seems super redundant. Is there another way to do this assuming the <code>tapped</code> function for each class does the same thing?</p>