As per my knowledge, Objective-C is an Object oriented programming languge and Categories is a feature provided by Objective-C.
So I would like to know that Category feature is coming under which OOPs concept
- Abstraction
- Polymorphism
- Encapsulation
- Inheritance, etc.
Thanks in advance.
Mrunal
@Abizern’s answer is good. I would add that categories are a form of dynamic dispatch, in particular that they can be used to extend existing classes without subclassing.
That said, Object Oriented Programming is more a design philosophy than a set of language features. One might ask “what OOP feature does postfix increment correspond to?” The answer is “none; it’s a language feature.” Categories are not primarily used to implement OOP design (though sometimes they are, as noted above). Their original use was to break up large implementation files. Their later use was to provide informal protocols due to a flaw in the language (lack of
@optional). And today, they’re primarily used to split code along platform-specific lines (NSString+UIStringDrawingvsNSString+AppKitAdditions).Extensions are similar to categories, and similarly are primarily a language feature rather than an OOP design feature. They facilitate encapsulation to some extent, but mostly are a side-effect of an arbitrary compiler requirement to define methods before they are used (I say “arbitrary” because this is not related to design or developer needs; it just simplifies the compiler). Extensions should not be confused with some deep OOP requirement.
So using categories to attach additional functionality at runtime is dynamic dispatch. Beyond that, it’s just a language feature that’s used for several non-OOP things.