Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > instantiates?

instantiates?
Thread Tools
Moderator
Join Date: Sep 2000
Location: Irvine, CA
Status: Offline
Reply With Quote
Sep 23, 2001, 01:02 AM
 
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
Reply With Quote
Sep 23, 2001, 02:15 AM
 
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!
Rick Roe
icons.cx | weblog
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Sep 23, 2001, 04:02 AM
 
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
Reply With Quote
Sep 23, 2001, 11:15 PM
 
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
Reply With Quote
Sep 24, 2001, 11:34 PM
 
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
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:19 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2