---
title: "What are all the difference between categories and subclasses?"  
description: "What are all the difference between categories and subclasses?"  
author: "Tarun Kumar"  
published: 2015-08-05  
updated: 2020-09-23  
canonical: https://www.mindstick.com/interview/12758/what-are-all-the-difference-between-categories-and-subclasses  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# What are all the difference between categories and subclasses?

**Category is a feature of the Objective-**C language that enables you to add methods (interface and implementation) to a class without having to make a subclass. There is no runtime difference—within the scope of your program—between the original methods of the class and the methods added by the category.

The methods in the category become part of the class type and are inherited by all the class’s subclasses. As with delegation, categories are not a strict adaptation of the Decorator pattern, fulfilling the intent but taking a different path to implementing that intent.

The behavior added by categories is a compile-time artifact, and is not something dynamically acquired. Moreover, categories do not encapsulate an instance of the class being extended.

The Cocoa frameworks define numerous categories, most of them informal protocols. Often they use categories to group related methods. You may implement categories in your code to extend classes without subclassing or to group related methods. However, you should be aware of these caveats:

· You cannot add instance variables to the class.

· If you override existing methods of the class, your application may behave unpredictably.

## Answers

### Answer by Tarun Kumar

**Category is a feature of the Objective-**C language that enables you to add methods (interface and implementation) to a class without having to make a subclass. There is no runtime difference—within the scope of your program—between the original methods of the class and the methods added by the category.

The methods in the category become part of the class type and are inherited by all the class’s subclasses. As with delegation, categories are not a strict adaptation of the Decorator pattern, fulfilling the intent but taking a different path to implementing that intent.

The behavior added by categories is a compile-time artifact, and is not something dynamically acquired. Moreover, categories do not encapsulate an instance of the class being extended.

The Cocoa frameworks define numerous categories, most of them informal protocols. Often they use categories to group related methods. You may implement categories in your code to extend classes without subclassing or to group related methods. However, you should be aware of these caveats:

· You cannot add instance variables to the class.

· If you override existing methods of the class, your application may behave unpredictably.


---

Original Source: https://www.mindstick.com/interview/12758/what-are-all-the-difference-between-categories-and-subclasses

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
