Monday, August 3, 2009

Objective C Part 2

What are Protocols?
For the uninitiated, Protocols can be considered to be similar to Interfaces. Protocols are used for multiple inheritance of specifications.
There are two kinds of protocols: informal and formal.
Informal protocol is list of methods a class CAN implement. The compiler does not know about it. These are optional methods a delegate of a class MIGHT implement. At runtime, the class figures out whether any delegate implements these methods or not.
Formal protocols are set of methods a class declares it WILL implement(eg Interface). The compiler then makes sure that the class implements these methods.

Objectice C suports dynamic typing?
This means that most type checking, eg whether int is really coming in the parameter of a method(?), is done at compile time. So there's more chances of runtime errors. Unit testing becomes more important in dynamic type languages.

Forwarding in ObjectiveC?
As we know Objective C objects accept messages. And mostly it's up to object to do anything with that message or not. One other thing an object can do is to forward this message to another object. This is supported by forward() kindof method in base Object class. The class must define this method and forward any message it seems fit.

Categories in Objective C?
What if a class is doing a lot of things(has many responsibilities). the methods get intermingled, and it's difficult to see what each method is doing. What if we could group sets of similar responsibility/functionality methods and say, kept them in different file. Then we could add these functionality oiented methods to class at runtime. Clean code. These groupings of methods are called Categories.

Garbage collection in Objective C?
Garbage collector(an optional conservative yet generational garbage collector) was introduced ObjC 2.0. But it's not part of ObjC2.0 for iPhones.

Standard libraries fo Objective C?
GNUstep on linux and Cocoa on Mac.

http://en.wikipedia.org/wiki/Objective-C

No comments: