[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Swarm-Support] passing information between classes
From: |
Derek Farren |
Subject: |
Re: [Swarm-Support] passing information between classes |
Date: |
Tue, 12 Oct 2004 18:21:37 -0300 |
Thanks a lot Rick and Paul!!!
That was an exelent explanation.... all my doubts were resolved, and now I
can see thta I have circularity problems.
Derek
----- Original Message -----
From: "Paul Johnson" <address@hidden>
To: "Swarm Support" <address@hidden>
Sent: Tuesday, October 12, 2004 12:47 PM
Subject: Re: [Swarm-Support] passing information between classes
> The two declarations do basically the same thing, however the compiler
> gets more information if you do
>
> ClassA * aClassA;
>
> This tells it where to look for the right methods.
>
> If you just do the id method, and the compiler finds 2 similarly named
> methods in different classes, then it may complain it is confused about
> the multiple declarations. You see, if you declare
>
> id aClassA;
>
> you have not really declared a ClassA object. You declared a generic
thing.
>
> In Swarm, protocols are frequently used, and if there is a protocol
> ClassA, the confusion is avoided if you do
>
> id <ClassA> aClassA;
>
> If
>
> Class * aClassA
>
> will work, I generally like to use it, for simplicity. Sometimes it will
> not. Here are some instances.
>
> in a header file ClassB.h, doing this may fail becuase "ClassA.h" is not
> included in the headers. It is not possible to include the header file
> because it would create a circularity, i.e., ClassB.h already includes
> ClassA.h.
>
> Incidentally, there's a class declaration that can be used to fix this.
> WIthout including ClassA.h, you can put an instruction in ClassB.h to
> tell the compiler to allow you to use ClassA * aClassA even though
> ClassA.h is not included. I think I saw that recently in ArborgamesII.
>
> The other time ClassA * aClassA will not work is when you are building
> an instance of a Swarm class that is designed to block subclassing and
> direct instantiation. I'm out on the edge of my precise understanding
> here. I know for sure that Swarm collections, such as List, will
> prohibit you from making instances like
>
> List * aList;
> aList = [List create: self];
>
> and the only option is
>
> id <List> aList
> aList = [List create: self];
>
> I know I've answered this question several times recently, but did not
> formalize a SwarmFaq entry about it. This is a start
>
> http://www.ku.edu/~pauljohn/SwarmFaq/SwarmOnlineFaq.html#7.6
>
> but I'll do more
>
> Derek Farren wrote:
> > Hello everybody.
> >
> > I have a doubt about passing information between classes. It ends on a
> > specific question: Whats the diference between creating an instance of
the
> > class "ClassA" via id aClassA and ClassA * aClassA ?
> >
> > Sometimes both ways work, but some other (when the imported class is
> > ModelSwarm) just the first choice works.
> >
> > 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
> _______________________________________________
> Support mailing list
> address@hidden
> http://www.swarm.org/mailman/listinfo/support