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 trialjungwook ryu
4,004 PointsDoes Swift not have abstract class?
I have some experiences with Java. so I think that your example is appropriate to use abstract class than Interface. (In Java) abstract class Employee { abstract void pay(); } Does Swift not have the concept like "abstract class" of Java?
3 Answers
alexlazau
10,930 PointsFor anyone who reads this question: Swift does not have abstract classes. I recommend changing your programming paradigms when working with Swift. Instead of embracing classes and inheritance, Swift delivers its full power when working with value types and composition. Here is a great WWDC session concerning this topic: https://developer.apple.com/videos/play/wwdc2015/408/
Paolo Scamardella
24,828 PointsAs far as I know, there is no abstract classes in Swift.
Trevor Duersch
9,964 PointsSounds similar to implementing a protocol. Then if you want to take it a bit further, you can do extensions on the protocols to get the patterns of abstract classes. Do a google search and you can probably find more information.
Duncan Hall
6,417 PointsDuncan Hall
6,417 PointsSo, if we wanted to make sure that all
Employee
s implementPayable
, what would we do?