Figure 15.1 "Object Diagram for DateList" errata?


#1

I was looking at this diagram to see if it would help improve my understanding of pointers and so forth. I found that it’s inconsistent, which suggests to me that it contains errata. For example, “now” points to the first instance of “NSDate”. I think this is correct. But, “tomorrow” points to the contents of the second instance of “NSDate”, which I believe isn’t correct (it’s being pointed to by NSArray[1]. Long story short: is this diagram incorrect, and would someone please tell me how it should have been drawn? Perhaps even more importantly, if it is correct, then why?

Thanks, Barry


#2

The diagram is correct.

Why is it correct? Because I drew it. :slight_smile:

I don’t understand the question. now, tomorrow, and yesterday are pointers to instances of NSDate. dateList is a pointer to an instance of NSArray, which just happens to contain pointers to NSDate objects.


#3

Hi Aaron,

Okay, I’ll take your word for it! Perhaps I’m taking the end points of the arrows too literally. For example, ‘now’ is pointing at the top of the first (top) instance of NSDate whereas ‘tomorrow’ is pointing at the lower rectangle of the second instance. That lower rectangle to me seems like a memory location. So, it seems odd that they point at different areas, as if in the first instance they mean one thing and in the 2nd and 3rd they mean something else.

This pointer-to-an-address concept has always been a little challenging for me to grasp and I know how important it is, which is why I’m reading this all so carefully. Still, I trust with repetition and practice it’ll all become clear.

Thanks for your feedback,

Barry


#4

“I was looking at this diagram to see if it would help improve my understanding of pointers and so forth. I found that it’s inconsistent, which suggests to me that it contains errata. For example, “now” points to the first instance of “NSDate”. I think this is correct. But, “tomorrow” points to the contents of the second instance of “NSDate”, which I believe isn’t correct (it’s being pointed to by NSArray[1]. Long story short: is this diagram incorrect, and would someone please tell me how it should have been drawn? Perhaps even more importantly, if it is correct, then why?”

now, tomorrow, and yesterday are all NSDate objects which we reference by pointers (locations in memory) *now, *tomorrow, *yesterday. As stand alone objects there is not really a first instance just objects located in memory via pointers. After placing these objects in an NSArray, then we kinda have 1st, 2nd, and 3rd objects but only in reference to iterating(stepping) though the array.
The diagram don’t number the three NSDate objects on the right side. The diagram intent is just to show us that the three instances of date objects point to three locations in memory. Plus the NSArray we created contains points to these three instances of date objects.

Hope this helps. Someone please correct me if my interpretation is wrong.