what are the advantages & disadvantages of using categories ? Why & When we need them ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Advantages:
You can extend any class, even those, for which you do not have the source. Look, for example, into the UI extensions added by Apple to the
NSStringclass for rendering, getting the metrics, etc.Since you have access to all instance variables, categories provide you with a nice way to structure your code across compilation units using logical grouping instead of the “it must all be in one phyiscal place” approach taken, for example, by Java.
Disadvantages:
AFAIK, the languages makes no guarantees as to which implementation will actually be called if you try something like: