swarm-support
[Top][All Lists]
Advanced

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

RE: Java examples


From: Charles Staelin
Subject: RE: Java examples
Date: Tue, 8 Feb 2000 15:14:24 -0500

Marcus,

Thank you.  I'm getting there.  I can instantiate classes
just fine using the API and then use the methods in them.
Where I get confused, however, is in using a method such as

getIntegerWithMin$withMax(-1, 1)

I know that I can use the method in one of my own by
importing Swarm.Globals and then referring to the method as

i = Globals.env.uniformIntRand.getIntegerWithMin$withMax(-1,
1);

Following the API from Globals through env through
uniformIntRand I even see how this works, but I'm not sure
that by looking first at getIntegerWithMin$withMax I could
have followed the path in the other direction.  Indeed, it
would seem more logical to use this method by including
(oops, importing) swarm.random.UniformIntegerDistImpl and
then getting at the method through this implementation
class.  However, I don't seem to understand how to actually
refer to the method this way.  Do I actually have to create
an instance of the UniformIntegerDistImpl class as in

UniformIntegerDistImpl r = new UniformIntegerDistImpl;

and then say

i = r.getIntegerWithMin$withMax(-1, 1);  ?

Or can I just refer to the class method without creating an
instance of the class?  Or am I entirely missing something
obvious?

Thanks,
Charles

-----Original Message-----
From: address@hidden
[mailto:address@hidden Behalf Of Marcus
G. Daniels
Sent: Monday, February 07, 2000 5:17 PM
To: address@hidden
Subject: Re: Java examples


>>>>> "CS" == Charles Staelin <address@hidden> writes:

CS> The problem is not the OOP stuff,
CS> but rather what needs to be in the include statements
and how
CS> particular methods in the various classes are properly
referred to.

You need to import each class or interface that you want to
use, or
use a wildcard expression that does the same.

At
http://www.santafe.edu/projects/swarm/swarmdocs/refbook-java
/index.html,
under "All Classes" are all the interfaces and classes.
When you
click on one of these, the documentation for that feature is
shown on
the right.  Note that the Java package is listed in small
letters
above the interface/class name.  It is the combination of
the package
and class/interface name that you use as the argument to
import.

Interfaces are the preferred data type for variables and
argument
types.  Interfaces either have no suffix, or a "C" or "S"
suffix.  The
common `using phase' methods are named by interfaces without
a suffix.
The methods you use when you are describing an object to
instantiate
it are in the interface with the "C" suffix (the `creating
phase').
The "S", `setting phase' methods are usable in either using
or
creating phase.

The actual implementation classes have the suffix "Impl".
Whenever
you want to instantiate an object, you'll use one of these
as an
argument to "new", and most of the time it will be with a
class in
the using phase, not the creating phase.  (The reason for
this is
that most using-phase implementation classes have `common
usages'
of just a few arguments, that take care to run the creating
phase,
apply the arguments, and then finish it in one step.)

Typical code for creating an object and assigning to a
variable is:

  Something obj = new SomethingImpl (aZone);


                  ==================================
   Swarm-Support is for discussion of the technical details
of the day
   to day usage of Swarm.  For list administration needs
(esp.
   [un]subscribing), please send a message to
<address@hidden>
   with "help" in the body of the message.



                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

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