Home > Iphone, Programming > Objective-C Basic knowledge

Objective-C Basic knowledge

This is small thing that i learned today while riding the train to buy some instant noodle in other town ^^.

From the Object Oriented Programming perspective, There is some difference between Objective-C and and other languages such as that derived from Simula, like C++, Java and C#. For non object operations, Objective-C are identical with C.

In objective-C, we don’t invoke a method, but instead send a message. Invoking a method implies that you know something about that method, while Sending message leaves it up to the message to figure out what to do with it.

This make Objective-C loosely coupled, that  make it much more dynamic at runtime than simula derived languages. In simula derived language you must know the type of an object before you can call the method. While in Objective-C, you simply send object with a message, then the receiving object try to interpret that message. In this case there is no guaranty of response, if Object doesn’t understand the message, it will return “nil”.

The other difference is in the way memory is managed. in Java there is Garbage Collection to handle memory management. Garbage collection frees the developer from manually managing the memory, but it routine consume additional computing resource.  Objective-C using “Reference counting”. This is a form of garbage collection, which count the number of reference to an object and frees the associate memory when the number of reference reach zero. The main advantages of reference counting over classic garbage collection is that memory is freed as soon as it no longer in use.

Almost Objective-C applications (Iphone Apps), uses Model-View-Controller (MVC) pattern. Rather than encouraging us to create subclass, MVC make use of delegate classes. MVC divide application into 3 functional pieces:

  • Model : Manage the application state and associate data. it’s entirely decoupled from the UI or presentation of application state to the user
  • View : is what user sees, and it displays the model for the user. It allow user to manipulate it and respond, and generate events
  • Controller : coordinates update of the view and the model when user interaction make changes to the model, and vice versa

Basic Objective-C Syntax :

Variable declaration look much same as other languages, method call are surrounded by square bracket.  For Example:

[anObject someMethod];  // The someMethod message is send to the anObject object.

[anObject someMethod : anotherObject]; // The someMethode message is sent to the anObject object and passes anotherObject as an argument

Categories: Iphone, Programming
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: