I understand Objective-C categories and how they become useful, but I always have a hard time explaining the concept to other programmers that are not familiar with Objective C.
Maybe I’m just bad at explaining things, but I was thinking at another way to explain it by comparing to similar features offered by other (more popular) languages. (ex : I can explain the similarities between Objective C protocols and Java Interfaces)
Any examples similar to Categories ?
3
C#’s class extension methods are basically the same thing done safely: you can only define methods that don’t already exist, you can’t violate encapsulation, and you can’t compile code that imports the same extension method twice from different static classes.
I dont have much experience with Objective C.
However, from what I’ve read, the Scala: Traits or Mixin Class Composition seems to be closest to categories. Alternatively its a special case of multiple inheritance perhaps (C++).
I dont think Java has anything quite like it.
1