Re: beginning Obj-C
Re: beginning Obj-C
- Subject: Re: beginning Obj-C
- From: "Anthony Byrne" <email@hidden>
- Date: Thu, 7 Aug 2003 14:07:52 -0500
>
All that said... I will be very grateful to any of you who are inclined
>
to read through all this and help me in getting over a couple of early
>
humps I've hit in understanding Objective-C.
...
>
The analogy is: Is saying "id anObject;" merely declaring an object
>
without saying what type of object it is, simply because objective-C
>
allows us to change what type of object it might be during runtime? Is
>
that it?
I think you are mostly on track, but maybe I can point something out that
will be helpful. With an object pointer, you can think of it's type in two
distinct ways: 1) it's static type, and 2) it's dynamic type.
The static type is the type you declare it as (i.e. an id or an NSControl*),
and that type never changes. The dynamic type is the type of object that
the pointer _really_ points to. The dynamic type could be any descendant of
the static type in the inheritance hierarchy. This is one of the most
powerful features of an object-oriented language. For example, you might
keep a generic list of NSControl pointers (their static type) that you might
periodically go through and enable or disable. Each one could have a
different dynamic type (NSButton, NSTextField, etc), but for your purposes
you don't care about that. All you care about is that it is an NSControl,
so it can be enabled/disabled.
The static type of "id" is completely generic, but there are times when
that's as specific as you can be. In the chapters ahead (getting back to
the ObjC.pdf doc) you will see that Objective-C provides ways for you to
inquire about an object's dynamic type at run time. Powerful stuff.
I'm still a bit new to Obj-C myself, so any of you old-timers feel free to
correct me. Many years of C++ have clouded my view somewhat, but I think
I'm starting to get it.
Hang in there, David, and good luck.
Tony Byrne
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.