Elements of the Language
Objective-C extends the C language with the following concepts and constructs:
Objects (instances of classes)
Classes
Inheritance and subtyping
Fields
Methods and method calls (or messages)
Categories
Protocols
Declarations (extended from C to include class and protocol types)
Predefined types, constants, and variables
Compiler and preprocessor directives
The following sections will describe these aspects of Objective-C.
Objects
Objects are the compound values—data and operations—at the heart
of object-oriented programming. They are generalizations of simple
structured types found in C and many other languages. Like C structs,
objects have components—data fields—that maintain state. For example,
a Book object might have fields to
specify the author and publisher. In addition, objects interact
through message passing, which provides an alternative to the function
calls of a procedural language.
Objective-C objects have these attributes:
- Class
An object type. An object whose type is
MyClassis said to be an instance ofMyClass.- Fields
Data members of an object. An object has its own copies of the fields declared by its class or its ancestor classes.
Note
Fields are also referred to as "instance variables.” I prefer the term “fields” for several reasons: “instance variables” is redundant since there are no class variables, it is ambiguous since it could mean variables that are instances, just “variables” would be more ambiguous, and “fields” is shorter. (An alternative term is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access