The Objective-C 2.0 Programming Language
This document is about the first component of the development environment-the programming language and its runtime environment. It fully describes the Objective-C language, and provides a foundation for learning about the second component, the Mac OS X Objective-C application frameworks-collectively known as Cocoa. You can start to learn more about Cocoa by reading Getting Started with Cocoa. The two main development tools you use are Xcode and Interface Builder, described in Xcode User Guide and Interface Builder respectively.
As the name implies, object-oriented programs are built around objects. An object associates data with the particular operations that can use or affect that data. In Objective-C, these operations are known as the object’s methods; the data they affect are its instance variables. In essence, an object bundles a data structure (instance variables) and a group of procedures (methods) into a self-contained programming unit.
For example, if you are writing a drawing program that allows a user to create images composed of lines, circles, rectangles, text, bit-mapped images, and so forth, you might create classes for many of the basic shapes that a user can manipulate. A Rectangle object, for instance, might have instance variables that identify the position of the rectangle within the drawing along with its width and its height. Other instance variables could define the rectangle’s color, whether or not it is to be filled, and a line pattern that should be used to display the rectangle.ARectangle classwould have methods to set an instance’s position, size, color, fill status, and line pattern, along with a method that causes the instance to display itself.
In Objective-C, an object’s instance variables are internal to the object; generally, you get access to an object’s state only through the object’s methods (you can specify whether subclasses or other objects can access instance variables directly by using scope directives, see “The Scope of Instance Variables” (page 36)). For others to find out something about an object, there has to be a method to supply the information. For example, a Rectangle would have methods that reveal its size and its position.
Moreover, an object sees only the methods that were designed for it; it can’t mistakenly perform methods intended for other types of objects. Just as a C function protects its local variables, hiding them from the rest of the program, an object hides both its instance variables and its method implementations.
…
Website: developer.apple.com | Filesize: 1266kb
No of Page(s): 155
Click here to download The Objective-C 2.0 Programming Language.
Related Tutorial
Tags: Enumeration, exception handling, Mac OS, Messaging, Object Oriented, Objective C, properties, static members, threads
Comments
Leave a Reply