Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Andrew Tuzson
Andrew Tuzson
21,802 Points

Modeling Behavior with Protocols Question

In this video, Pasan explains that when you have two classes that are similar with similar method implementations, a protocol is the best solution for achieving this elegantly. That makes sense. However, some additional research has led me to discover polymorphism and it sounds like that is also a preferred approach, whereas you could simply use the base class to model the functionality and update these methods in the subclasses.

So, I have two questions. First, is my understanding of polymorphism correct? I am still rather new to all of these concepts. Second, do protocols trump polymorphism and when would you use one over the other?

Thanks!