0

I've realized there's no abstract classes in Objective-C. Is there any way to achieve the same functionality in some other way (a class that can't be instantiated, or methods that MUST be overridden by their subclass)?

jscs
  • 63,694
  • 13
  • 151
  • 195
maor10
  • 1,645
  • 18
  • 28

1 Answers1

1

It depends exactly what you want. If you would just use the class as an interface with no implementation then using a protocol instead is best. If you need some base or default implementation then you either document that the class shouldn't be instantiate do directly (common nowadays I think) or you implement the class to throw exceptions if it is instantiated directly (uncommon nowadays). Also throw exceptions in any methods that should be implemented by a subclass and are called on the superclass.

Unless you're creating a framework that will be delivered to other developers it's generally not worth the effort to implement, just document.

Wain
  • 118,658
  • 15
  • 128
  • 151