Re: Classes and the Production of Objects
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 14:16:29 +0200
On Saturday, August 10, 2002, at 09:41 , terry wrote:
I'm going to take a shot at answer this, even though my Cocoa skills aren'
t quite up to par yet. ;) (A lot of this is similar to Java/C++)
Actually, C++ is the biggest hurdle in learning any dynamic
object-oriented language: it teaches you all the wrong things. (Java's
somewhat better, though still not perfect.)
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?
No, an object is only created when you specifically instantiate an object.
Nope. The class is an object too. Whenever the difference is important
(like here), the object you instantiate is, surprisingly, an instance.
The class is a template for an object. Think of it as a blueprint. You
can have a blueprint of a house, but that doesn't mean you have a house.
It means you have instructions for a house.
Yup. And the blueprint of course is *another* object: not a house, but an
object of different kind. It's the class.
I'm not sure if you *can* have class variables... can someone else
elaborate there?
Right, you can't.
I do know that class methods are specific to the class, they do not
extend to object, and object methods do not work with a class declaration,
even though they are defined in a class declaration. :)
Ouch...
(a) there are class methods (+). They are used when the class receives a
message. They have nothing to do with the instance object;
(b) there are instance methods (-). They are used when an instance
receives a message. They have nothing (but for some hidden implementation
details) to do with the class object.
...NSFoo does look up the "doFoo" message in it's "selector table" (Is
that the correct terminology?)
Not quite, but the difference is negligible (AFAIK, it's called method
table ;)
In other words, classes can *not* (to my knowledge) act upon "-" methods,
and objects can *not* (to my knowledge) act upon "+" methods. They're
separate.
Do please call those "objects" of yours instances, for that's what they
are (classes are objects too). But for this, precisely. Those sets of
methods are completely separate.
A class' job is specifically to create and deal with it's objects. It
doesn't deal with anything else. (AFAIK)
It can deal with more or less anything else, but usually does not.
Objective C seems to be *much* like Java and C++ in some respects. Class
methods exist in Java, and they behave pretty much the same way...
Up to some limitations which soon become paramount -- like that you can't
use this (ObjC self) or super in Java's class methods. Or that you can't
include class methods in interfaces (ObjC protocols).
I *think* you can do something similar in C++, but I haven't seen it much.
No, you can't. The best bet is RTTI and dynamic services, but still it's
far from a dynamic language. A C++ class is more just a type than a
first-citizen object like in ObjC.
---
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.