Câu hỏi phỏng vấn Objective-C
Câu hỏi

When would you use Categories over Inheritance and vice versa?

Câu trả lời

Here is my attempt at answering your Objective-C interview question:

When to Use Categories vs Inheritance

Categories

Categories in Objective-C allow you to add methods to an existing class without subclassing. This is useful in a few key scenarios:

  1. Extending system classes - You can add methods to Apple's built-in classes like NSString or UIView to add functionality that is missing. This allows you to extend the capabilities of these classes without modifying the original source code.

  2. Organizing code - You can split a class's implementation into multiple categories, each containing related methods. This helps keep your code organized and modular.

  3. Providing optional functionality - Categories allow you to provide optional methods that a class can adopt if needed, without forcing all users of the class to include the extra code.

  4. Unit testing - Categories make it easy to isolate and test specific methods of a class in unit tests, by putting those ...

middle

middle

Gợi ý câu hỏi phỏng vấn

expert

Explain method swizzling. When you would use it?

middle

What's the difference between the atomic and nonatomic attributes?

middle

What is the purpose of managed object context NSManagedObjectContext in Objective-C and how does it work?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào