• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Classes and the Production of Objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Classes and the Production of Objects


  • Subject: Re: Classes and the Production of Objects
  • From: Ondra Cada <email@hidden>
  • Date: Sat, 10 Aug 2002 13:24:17 +0200

On Saturday, August 10, 2002, at 09:06 , Brendon Bruns wrote:

When you define a new class in a program, is an object created immediately
and automatically from that declaration (such as at runtime) or does the
class exist as raw code and need an instigator to make an object?

Instigator indeed ;)

Declaration of class makes "immediately" one (static) object: the class itself. It can then be sent appropriate messages ("alloc") to create other,
dynamic objects (its instances).

In my "Learning Cocoa" book, it is stated that a class can be assigned
methods and possibly have have variables that are created for it.

I did not read the book, but this is plain wrong. In ObjC, there are no class variables.

So in
relation to the question I stated above, does this mean that a class can
exist without creating an object

Exactly right.

and in fact, it can do some work?

Exactly right. (Instead of class variables normal static variables are used; full-featured class variables can be emulated using NSDictionaries in those very rare cases they are needed).

Or are
the methods there in place to tell the class to create an object?

Nope. Class methods can do just anything. As a matter of fact, you never implement a method which would create an object: +alloc does it, and you inherit this one.

Finally, does an Instance refer to the Object that has been created by the
Class and

Right.

it is the chunk of code in memory that actually processes data?

Wrong. If we should go low-level, then instance is the chunk in memory which *contains* the data. Among them, there is pointer to its class, and *it* contains the appropriate code (methods) that actually processes those data.

Therefore, an Instance would be another name for an active Object in
existence?

If I understand properly, yep.

There are two kinds of objects: classes (made statically at compile-time as "a sideeffect of class declaration"), and instances (made by classes as reponse of receiveing the "alloc" message).

(To be completely precise, a class in fact can be made dynamically in runtime too, but forget it till you are a very experienced ObjC programmer ;)
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.
References: 
 >Classes and the Production of Objects (From: Brendon Bruns <email@hidden>)

  • Prev by Date: Re: FTPClient Beta Released - Please test
  • Next by Date: Re: NSButton question
  • Previous by thread: Re: Classes and the Production of Objects
  • Next by thread: Re: Classes and the Production of Objects
  • Index(es):
    • Date
    • Thread