<$BlogRSDURL$> Plluke's Blog

You can put some words or titles or whatever up here...description? We'll customize...

6/28/2008

Subjective-C 

Reading through primer's for Objective-C, I'm struck by the use of new names for existing concepts. For example:

A protocol declares methods that can be implemented by any class. Protocols are not classes themselves. They simply define an interface that other objects are responsible for implementing. When you implement the methods of a protocol in one of your classes, your class is said to
conform to that protocol.
Interesting, so a protocol is just an interface that other objects implement. In other parts of the world, we call such an interface an interface.
A class in Objective-C can declare two types of methods: instance methods and class methods. An instance method is a method whose execution is scoped to a particular instance of the class. In other words, before you call an instance method, you must first create an instance of the class. Class methods, by comparison, do not require you to create an instance, but more on that later.
So instead of declaring methods static, we now have somewhat less expressive notations of "-" for instance methods and "+" for class methods. Class methods are different than static methods, Apple tells me, but why do we have to resort to "+"?
When you want to call a method, you do so by "messaging” the corresponding object. The message in this case is the method signature, along with the parameter information the method needs. All messages you send to an object are dispatched dynamically, thus facilitating the polymorphism behavior of Objective-C classes. In other words, if a subclass defines a method with the same signature as one of its parent classes, the subclass receives the message first and can opt to forward the message (or not) to its parent.
So the "message" you send (with quotes) is equivalent to calling a method (without quotes). Also, what part of polymorphic inheritance isn't already part of other OOPLs, like Java?

Final gripe that may just be a n00b question: If the "messaging" syntax is represented by [object :parameter], how do you do method chaining?
[[[object method1:parameter1] method2:parameter2] method3:parameter3]?
That looks ugly.

Still wondering why we need another language to program on a different platform but maybe I'll change my mind once I delve deeper. For now, Apple seems to be continuing to do its thang of making a big deal out of existing concepts. XCode does "Data Tips". Great. What other decent IDE doesn't?


// posted by Me @ 6/28/2008 03:31:00 PM

This page is powered by Blogger. Isn't yours?