What is the difference between inheritance and Categories in Objective-C?
What is the difference between inheritance and Categories in Objective-C?
The main differences between inheritance and categories in Objective-C are:
Inheritance allows a class to inherit properties and methods from a superclass, creating a hierarchical relationship between classes[1][3]. A subclass inherits all the instance variables and methods from its superclass, and can add new methods or override inherited ones[1][3]. Objective-C supports single inheritance, where a class can have only one superclass[1].
Categories, on the other hand, allow adding methods to an existing class at runtime, without subclassing[2]. Categories are used to extend the functionality of a class by adding new methods, or even overriding existing methods[2]. Unlike inheritance, categories do not inherit instance variables from the class they extend[2]. Categories are commonly used to add functionality to system classes like NSString...
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào