swarm-support
[Top][All Lists]
Advanced

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

Re: copy method


From: glen e. p. ropella
Subject: Re: copy method
Date: Thu, 13 Feb 1997 10:53:00 -0700

> Glen, have you thought of the possibility of doing the copy
> method(s) in a protocol. I believe Roger or you mentioned that they
> kept wanting to use multiple-inheritance to handle this. Protocols
> is the means by which Obj-C mimics multiple inheritance. Protocols
> are also not really OO, which may appeal to you as a solution (since
> you said OO was the problem).

Well, since I've only been using the OO paradigm for 5 months now (and
that's an overestimate because of the learning curve), I'm probably
not aware of the differences between the OO-ness of protocols and any
so-called classical OO.  I'd assumed that inheritance was an OO
concept, and, hence, multiple-inheritance was too.  However, I do
notice that they free one (somewhat) from the hyper-strict class
hierarchy.  Please feel free to correct me on any issue.  I am 
decidedly novice in this area!

But, is this problem solvable with protocols?  I have a "universe"
object (say, a modelSwarm), that is responsible for creating some
member objects (say, heatbugs) and giving them the initial properties
necessary to function in the universe (say, a spot in a lattice, an
ideal temperature, etc.).  Now, assuming the universe wants to "clone"
one of those bugs, if I put the copy method in the bug class, then I
get the benefit of hiding the need (or lack thereof) for a fully
specified copy.... i.e. the bug's class should know best what is
required to obtain a fully functional clone of one of its instances.

Now, there's no *real* problem with this.  However, there is a model
specification problem.  The universe is responsible for initialization
of bugs but not for the cloning of bugs.  That's an unnatural and
highly artificial division.  But, it is present because of the OO
technology we're using because the relevant information is *class*
specific, making it a good programming decision to put the copy in the
class.

Now, how can I use protocols for this?  I'd like the universe object
to accept a "- (id) copy: (id) bug;" message.  But, from the
programming perspective I'd like the bug to do the actual copy.  So
the bug might accept a message specified as "- (id) copy;".  Can a
protocol do this kind of mapping?  Or would it be necessary to create
a method in the universe object that took the former message and
reformulated it to send it to the bug argument?

Now, like I said, in some ways, this is a non-issue.  It's really
trivial.  But, it leads one *away* from thinking about how they want
their model to work and *toward* how to program.  The whole gist of
what simulation tools should be doing (and, in my minority opinion,
what programming tools, in general, should be doing) is leading *away*
from thinking about how to program and *toward* thinking about how to
model.  So, yes, I'm using this as a whipping-boy to re-adjust my
thinking.  But, that doesn't mean that the target issue isn't
important. [grin]

[Whew!]

glen


reply via email to

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