Graphics Programs Reference
In-Depth Information
Objects
Let's say you need a way to represent a party. Your party has a few attributes that are
unique to it, like a name, a date, and a list of invitees. You can also ask the party to do
things, like send an email reminder to all the invitees, print name tags, or cancel the party
altogether.
In C, you would define a structure to hold the data that describes a party. The structure
would have data members - one for each of the party's attributes. Each data member would
have a name and a type.
To create an individual party, you would use the function malloc to allocate a chunk of
memory large enough to hold the structure. You would write C functions to set the value of
its attributes and have it perform actions.
In Objective-C, instead of using a structure to represent a party, you use a class . A class is
like a cookie-cutter that produces objects. The Party class creates objects, and these ob-
jects are instances of the Party class. Each instance of the Party class can hold the data
for a single party ( Figure 2.1 ).
Figure 2.1 A class and its instances
 
Search WWH ::




Custom Search