10-05-2012, 12:12 PM
Object-Oriented Programming with Objective-C
OOP_ObjC.pdf (Size: 470.95 KB / Downloads: 46)
Introduction
An object-oriented approach to application development makes programs more intuitive to design, faster to
develop, more amenable to modification, and easier to understand. Most object-oriented development
environments consist of at least three parts:
● A library of objects
● A set of development tools
● An object-oriented programming language and support library
The Objective-C language is a programming language designed to enable sophisticated object-oriented
programming. Objective-C is defined as a small but powerful set of extensions to the standard ANSI C language.
Its additions to C are mostly based on Smalltalk, one of the first object-oriented programming languages.
Objective-C is designed to give C full object-oriented programming capabilities and to do so in a simple and
straightforward way.
Important This document does not describe the Objective-C language itself. To learn about the language,
see The Objective-C Programming Language .
Every object-oriented programming language and environment has a different perspective on what
object-oriented means, how objects behave, and how programs might be structured. This document offers
the Objective-C perspective.
Who Should Read This Document
For those who have never used object-oriented programming to create applications, this document is designed
to help you become familiar with object-oriented development. It spells out some of the implications of
object-oriented design and gives you a flavor of what writing an object-oriented program is really like.
If you have developed applications using an object-oriented environment, this document will help you
understand the fundamental concepts that are essential to understanding how to use Objective-C effectively
and how to structure a program that uses Objective-C.
2010-11-15 | © 2010 Apple Inc. All Rights Reserved.
Introduction
Because this isn’t a document about C, it assumes some prior acquaintance with that language. However, it
doesn’t have to be an extensive acquaintance. Object-oriented programming in Objective-C is sufficiently
different from procedural programming in ANSI C that you won’t be hampered if you’re not an experienced
C programmer.
Organization of This Document
This document is divided into several chapters:
● “Why Objective-C?” (page 7) explains why Objective-C was chosen as the development language for the
Cocoa frameworks.
● “Object-Oriented Programming” (page 8) discusses the rationale for object-oriented programming
languages and introduces much of the terminology. It develops the ideas behind object-oriented
programming techniques. Even if you’re already familiar with object-oriented programming, you are
encouraged to read this chapter to gain a sense of the Objective-C perspective on object orientation and
its use of terminology.
● “The Object Model” (page 12) describes how you can think of a program in terms of units that combine
state and behavior—objects. It then explains how you characterize these objects as belonging to a particular
class, how one class can inherit state and behavior from another class, and how objects can send messages
to other objects.
● “Structuring Programs” (page 29) explains how you think about designing an object-oriented program
by creating connections between objects. It introduces the techniques of aggregation and decomposition,
which divide responsibility between different sorts of object, and the role of frameworks in defining libraries
of objects designed to work together.
● “Structuring the Programming Task” (page 34) discusses issues of project management related to
collaboration among programmers and to code implementation.
See Also
The Objective-C Programming Language describes the Objective-C programming language.
Objective-C Runtime Programming Guide describes how you can interact with the Objective-C runtime.
Objective-C Runtime Reference describes the data structures and functions of the Objective-C runtime support
library. Your programs can use these interfaces to interact with the Objective-C runtime system. For example,
you can add classes or methods, or obtain a list of all class definitions for loaded classes.
Introduction
Organization of This Document
Why Objective-C?
The Objective-C language was chosen for a variety of reasons. First and foremost, it’s an object-oriented
language. The kind of functionality that’s packaged in the Cocoa frameworks can only be delivered through
object-oriented techniques. Second, because Objective-C is an extension of standard ANSI C, existing C programs
can be adapted to use the software frameworks without losing any of the work that went into their original
development. Because Objective-C incorporates C, you get all the benefits of C when working within Objective-C.
You can choose when to do something in an object-oriented way (define a new class, for example) and when
to stick to procedural programming techniques (define a structure and some functions instead of a class).
Moreover, Objective-C is a fundamentally simple language. Its syntax is small, unambiguous, and easy to learn.
Object-oriented programming, with its self-conscious terminology and emphasis on abstract design, often
presents a steep learning curve to new recruits. A well-organized language like Objective-C can make becoming
a proficient object-oriented programmer that much less difficult.