Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
12Activity
0 of .
Results for:
No results containing your search query
P. 1
Objective-C Overview

Objective-C Overview

Ratings: (0)|Views: 410|Likes:
Published by Nathan
A brief overview of Objective-C
A brief overview of Objective-C

More info:

Published by: Nathan on Oct 20, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/31/2011

pdf

text

original

 
Overview 
Objective-C is an object-oriented extension to the C language. It is C with a small number of extensions.Although the differences can fade into shades of grey, Objective-C is different from C++. C++ istraditionally associated with the Simula 67 school of object-oriented programming where Objective-Chas SmallTalk roots. In C++, the static type of an object determines whether it can receive a message.In Objective-C the dynamic type of an object determines whether it can receive a message. The Simula67 format is more structured and allows problems to be detected earlier when a program is compiled.The Smalltalk approach delays it's typing until runtime and is touted as a more flexible alternative.This flexibility extends the language into three separate areas: Dynamic Typing, Dynamic Binding andDynamic Loading.
Dynamic Typing
As opposed to other languages, Objective-C delays the typing of language objects until a program is executed at run time. The method name, type and argument information as well asclass variable instance information are available to provide the essential support for DynamicBinding. This might by likened to the System Object Modules (SOM) and it's InterfaceDefinition Language (IDL) that Apple has been using for it's more recent object-oriented systemadditions.
Dynamic Binding
Methods and classes may be added or deleted at run time. The resulting list of objects are boundtogether during run time using the Dynamic Typing information. This provides the flexibility todevelop programs in pieces using stepwise refinement to create an initial version of a programand then later during the maintenance phases of a programs life to incrementally change thecomponents of a program.
Dynamic Loading
Finally, program segments are not loaded into memory until they are actually used therebyminimizing the system resources required for an instance of a program. In Objective-C all of this is bound into the language and it's run time. Objective-C is possibly one of the best blendsof traditional system programming language features and object-oriented programming features.
History 
Objective-C was developed by Brad J. Cox to add object-oriented SmallTalk-80 based extensions to theC language. A GNU version was written by Dennis Gladding in 1992 and the second version soonthereafter by Richard Stallman. The current GNU version is derived from the version written byKresten Thorup when he was a university student in Denmark in 1993. Kresten transported that versionto NeXT when he joined the firm later that same year.
 
Objective-C Components
Objective-C is organized as a series of object-oriented additions to the C language. It is important toremember that it is the ANSI C language at its core. In a typical Objective-C program, segments of traditional C are organized into strips of code and associated data which are executed under tightlyconstrained conditions. This new framework for C has a well defined family of components that must be understood for the overall program to make sense. The members of the Objective-C family are:
Objects
Objects associate data and operations. Objects are the root of the Objective-C family tree.
Methods
Methods are the operations that Objective-C applies to data.
Messages
Messages are the way one instance of a method requests another method to perform andoperation. For example [myrect display] asks the myrect method to perform the displayoperation.
Classes
Classses are how objects are defined. Classes contain the prototype object variables andmethods. Classes inherit variables and methods from a higher level class called a super-class. Aclass that inherits some or all of the methods and variables is a sub-class. In Objective-C allclasses are a sub-class of a primal super-class called Object.
Protocols
Protocols are ways to inherit part of a super-class or to extend a super-class.
Categories
Categories are ways to declare Methods that can be implemented by any class.
Remote Messages
Remote Messages support the distribution of objects into different threads of execution andacross different computers. Remote Messages are the heart of distributed application progressing.Multi-tiered distributed applications are one of the hallmark features of the OpenSteparchitecture.
Persistance
Objects and their data can be allowed to persist after the creating instance of an object hascompleted it's execution. This is an important and advanced feature of the OpenStep system.In traditional programming languages a function is called to perform an operation on a data object. InObjective-C and other object-oriented languages, a message is sent to an object asking it to performone of its methods on itself.
 A Practical Analogy 
Many file systems are organized into standard primitive operations such as:
Open - open or create a file
 
Close - close a file
Read - read data from a file
Write - write data to a file
Ioctl - perform file system specific operationsThe Open call usually returns some sort of identifier that is used in subsequent Read, Write and Ioctloperations. The identifier is valid until a Close call is made. In an object-oriented environment, theclass might be named FileSystem, the methods would be Open, Close, Read, Write and Ioctl. Theobject would be the file identifier that is returned by the Open call and binds all subsequent calls to asingle body of file information.
Objective-C Example
This example is also take from Gerrit Huizenga's course notes from an object-oriented language course taught atPurdue University. The URL for the course notes and other reference information are contained later in thereference section.
In Objective-C program segments are defined by an
interface
and an
implementation
. These are byconvention separated into two files. The interface file is named with a '.h' extension and theimplementation file is named with a '.m' extension.
Interface Definition
In Objective-C the interface to a class is defined using the @interface and @end pair of languagestatements.@interface Stack : ObjectDefines the Stack class as a subclass of the Object super-class. This declaration is followed by theinstance variables used to implement the object. Each instance of a class has it's own copy of thesevariables.
@interface Stack : Object{
 
StackLink *top;
 
unsigned int size;}
Defines the Stack class with instance variables top and size;Following this definition is a list of the names of the methods that implement this class.
 
- free;
 
- push : (int) anInt;
 
- (int) pop;
 
- (unsigned int) size;@end
Defines free, push, pop and size methods for the Stack class. The declaration is terminated with an@end statement. Method names contain a colon to separate the name of a method from its arguments.A colon is also used to separate arguments. For example:

Activity (12)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
Aditya Deshpande liked this
Aditya Deshpande liked this
iamhappymalls liked this
abhikumar1161453 liked this
cetatii542224 liked this
Joshua Dover liked this
deepardas liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->