Apple Mac OS is based on objective C language. This is the level of usage this language is having. For those who are new to programming languages, this article will provide you loads of information about Objective C language. Though there is vast usage of this language, this is not a standardized language. This also has the ability to send messages and other such applications. This language was initially developed by Apple Inc.
Brad Cox and Tom Love were considered the brain-child of objective C. In 1980, they used to work for a company called Stepstone. Cox was always interested in the reusability of programming. With the help of languages like Smalltalk he thought that he can develop an environment which will help ITT developers. He started working on C compilers and included some of the features of Smalltalk in it. After doing these modifications, he made the C compiler into an object oriented language. This gave birth to the “OOPC” (Object Oriented Programming in C).
Love and Cox later started their own company named “Productivity Products International”, which promoted their own brainchild. A book was also published by Cox which was used to describe Objective C language. The book was called Object Oriented Programming, An Evolutionary Approach.
Objective C is generally compared with C language. As the language itself was developed from C, there are lot of common features with C and OOPC. The programming in OOPC is dependent on variables, messages, interfaces and implementations, forwarding, protocols etc. With the usage of all the following elements, an efficient and productive application can be developed. These are the basic objects which one has to know about to learn the OOPC language.
Variables – Variables are the most common aspect of any language. They help in assigning a value to some the object. The default variable is ‘id’ which is used by objective C. By prefixing the syntax to the variable one can give a definite value to the variable or manipulate with the given data. There are many types of variables which are used in objective C language.
Messages – The most important function on which the programs of objective C are dependent on are messages. Messages are passed on to an object to carry forward or terminate a function. This process is called ‘method’ in other languages. In objective C, it is known as ‘sends a message’. The syntax for sending a message to the object in the program is – [obj method: argument];
Interfaces and Implementations – Both these functions are very important to describe a class in a particular program. Both the commands are kept in separate code blocks. The interface is placed in a header file and implementation is places in a code file.
Interface is usually used to define a class in the header file. For example game.h will have the interface of the class game. The header files are generally supported with the extension .h.
Implementations are the files in which the methods or the messages are described. These are generally code files. The messages which are supposed to be sent to the object are saved in code files. These files generally have the file extensions .m. They denote message files.
Forwarding – Normally when a message is not received by an object than the compiler usually considers it as an exception and carries on. But in objective C, the message which is not received is forwarded to an object which can respond. This happens through the implementation files. They are used to simplify certain design patterns in implementation. The syntax which is normally used for forwarding is –
- (retval_t) performv:(SEL) sel :(arglist_t) args; // with GCC
- (id) performv:(SEL) sel :(marg_list) args; // with NeXT/Mango systems