 |
 |
instantiates?
|
 |
|
 |
|
Moderator 
Join Date: Sep 2000
Location: Irvine, CA
Status:
Offline
|
|
I am sort of new to Cocoa programming.
I know what instantiates means, but can anyone put it in context with simple programming terminology?
Thanks.
|
|
{{{ mindwaves }}}
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
Sure, I'll give it a try.
When you have a "class" in an OO language, you have a description for a specific type of object. When you have an "instance" of a class, you have an actual object of that type. Thus, to "instantiate" is to create a new object which is an instance of a given class.
You instantiate an object whenever you do [NSThisOrThatClass alloc]. The new object is an instance of the class NSThisOrThatClass. You can also instantiate objects in Interface Builder. Select a class (perhaps one you've defined yourself) in the Classes tab, and choose Instantiate from the Classes menu. This creates an instance of the selected class, an object which will exist in your program when the nib file is opened.
Hope this helps!
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
For example, all windows in your Cocoa application instances of the NSWindow class, with their own content, title, location on the screen, etc. NSWindow defines what properties your windows should have, and how to make them display by talking to the window server, but it doesn't know where window X is on the screen. I hope that made sense 
|
|
|
| |
|
|
|
 |
|
 |
|
Moderator 
Join Date: Sep 2000
Location: Irvine, CA
Status:
Offline
|
|
Thanks for all of the help. I am still somewhat confused, but it is a lot clearer now. With a little more programming in Cocoa, it should be relatively easy to understand soon.
|
|
{{{ mindwaves }}}
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Here's how I think about : Your classes are molds for whatever you want to make. I can have a mold for making fruitcake, or a mold for making bricks, or even a mold for making imacs. With one mold, I can make several instances of the same type of object, although each object is unique. That means I can make 30 fruitcakes (type=fruitcake), and that would be my 30 instances. I can interact with each of my 30 fruitcakes individually, and know that there are certain ways to interact with my fruitcakes (I can eat them, but breathing them is deprecated  )
So when someone says they make an instance of their object, their just taking their mold and making a fruitcake.
The example my CS teacher used to explain instance varibales was clocks. First you define a type of Clock, so let's pick a PreciseClock because it will have hours, minutes, and seconds. There are certain things that all clocks must do, such as be able to increment seconds, increment minutes, and increment hours. So when I make an instance of a PreciseClock, I get out my mold and make my object to the specifications of a PreciseClock. Then I can tell my PreciseClock to incrememnt a second, increment a minute, whatever you want. And if I want to have two clocks, one for the time here, and one for the time in Russia, I can do that by making 2 instances of PreciseClocks (whip out my mold twice), and then incrementing the time until they are correct.
Did that make sense? Sorry if I was too confusing,
F-bacher
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|