Graphics Programs Reference
In-Depth Information
Figure 2.12 A BNRItem instance
Notice that Figure 2.12 shows a total of four objects: the BNRItem , two NSString s,
and the NSDate . Each of these objects is its own object and exists independently of the
others. The BNRItem only has pointers to the three other objects. These pointers are the
instance variables of BNRItem .
For example, every BNRItem has a pointer instance variable named itemName . The
itemName of the BNRItem shown in Figure 2.12 points to an NSString instance
whose contents are “Red Sofa.” The “Red Sofa” string does not live inside the BNRItem ,
though. The BNRItem instance knows where the “Red Sofa” string lives in memory and
stores its address as itemName . One way to think of this relationship is “the BNRItem
calls this string its itemName . ”
The story is different for the instance variable valueInDollars . This instance variable
is not a pointer to another object; it is just an int . Non-pointer instance variables are
stored inside the object itself. The idea of pointers is not easy to understand at first. In the
next chapter, you'll learn more about objects, pointers, and instance variables, and,
throughout this topic, we will make use of object diagrams like Figure 2.12 to drive home
the difference between an object and a pointer to an object.
 
Search WWH ::




Custom Search