Hacker News new | past | comments | ask | show | jobs | submit login

The idea behind Categories is to add methods to an existing class. This means if you get back an NSString from an API call, for example, you can call a method from a category declared on NSString, without having to convert it to the instance of some subclass. This can be very convenient, and I can't think of anyway to do the equivalent in Java.

It's similar in spirit to "monkey patching" in Ruby and similarly dynamic languages (but won't allow you to replace existing methods, so not as dangerous).




> It's similar in spirit to "monkey patching" in Ruby and similarly dynamic languages (but won't allow you to replace existing methods, so not as dangerous).

My understanding is that you can create methods with the same signatures, but which one will end up getting called is completely undefined, making it a worse idea that it usually is.

It can be very handy thing though, I really like it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: