swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swarm-Support] @class and @public


From: Paul Johnson
Subject: Re: [Swarm-Support] @class and @public
Date: Wed, 09 Feb 2005 06:37:21 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041127)

@public means an instance variable can be accessed "directly" with -> from outside the object. It essentially makes the object's values accessible as if it were a C struct. It gives quick access to values, but is dangerous because you might accidentally change values. By default, IVARS are "private" and the usage like anObject->x will be rejected by the compiler. THe "object oriented religion" holds that people should not write code this way, but sometimes you can get speedups if you avoid it. If you constantly have to do [anObject getValue] you impose more overead on the runtime than if you have a public variable obtained with anObject -> x. In the Pentium 75 days, a few hundred thousand of those would really add up. But I've not noticed it so much lately :;

The #import (or include) includes a header file where a class and its methods are defined. It tells the compiler where to look for methods.

If you use @class Abc, you are not really including a class, but you are promising the compiler that you will define it later. THat silences the warnings. This is used as a way to avoid "circular includes". You can't include two h files in each other. Suppose there are 2 classes.

A.h A.m

B.h B.m

In A.h, you want to declare a variable

B * myThing;

If B.h imports A.h, you can't import B.h in A.h, The compiler is confused because, whichever one gets found first by the compiler will fail because it can't find the o file for the other. So to fool the compiler, you promise it that class will come along later. I recall using that trick in a couple of projects, but I never found a full manual length treatment of it.

The alternative work around is, in A.h, to declare

id myThing;

and then import B.h in A.m. Then the compiler might not get too confused about where it is supposed to find methods for myThing.

I say might not because the newest gcc seems to whine and complain and warn about everything, even stuff we've been doing since before the dawn of time. Or the introduction of the Pentium, which ever came first :)

I hope I've not misled you. I'm just giving you back the information I've gleaned from conversations in this list.

pj


Derek Farren wrote:
Hello Swarm friends.
What´s the difference between includeing a Class named Abc by "#include Abc.h" and @class Abc?
Also, what does @public before the definition of a variable mean?
Thanks, Derek


------------------------------------------------------------------------

_______________________________________________
Support mailing list
address@hidden
http://www.swarm.org/mailman/listinfo/support


--
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ku.edu/~pauljohn
1541 Lilac Lane, Rm 504
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66044-3177           FAX: (785) 864-5700


reply via email to

[Prev in Thread] Current Thread [Next in Thread]