swarm-support
[Top][All Lists]
Advanced

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

Re: [Swarm-Support] Questions about passing SwarmObjects within other ob


From: Paul Johnson
Subject: Re: [Swarm-Support] Questions about passing SwarmObjects within other objects
Date: Wed, 08 Sep 2004 17:02:52 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040803

Hi, Paul:

Here's the answer.

id world;
HeatSpace * world;
id <some_protocol> world;

are all acceptable. id means a "pointer to an object", so you don't put a * there, since the pointer idea is in the heart of it.

The advantage of declaring

HeatSpace * world;

is that the compiler knows exactly where to find methods for the world object to use. It is one way to solve the problem that, if you declare a method slightly differently in two classes, the compiler will complain to you. Suppose you have

- (double)getValue;

in the HeatSpace class, and

- (int)getValue;

in another class.  If you used the declaration

id world;

and then

[world getValue];

The compiler will complain that various methods "getValue" were found and it will bother you because their signatures are not exactly the same.

On the other hand, with

HeatSpace * world;

it knows exactly which class you are using, so its not confused by the difference in method names.

In some Swarm classes, you are wise to include protocol declarations. You are not supposed to declare things with class names. I don't recall exactly which ones, but if you grab some 4 year old swarm code, you will find the problem right away when you try to compile. It does not want you to do things like

ZoomRaster * aRaster;

or was it:

Grid2d * world;

?

Rather, it wants


id <ZoomRaster> aRaster;
id <Grid2d> world;



Paul Thompson wrote:
I'm Paul Thompson, a graduate student at Rochester Institute of

Below is the oft-perused ObserverSwarm of the heatbugs app.  My
concern is with the variable declaration for world and HeatSpace. More precisely, why is world declared as a variable while HeatSpace is
declared as a pointer?




--
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]