[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possible to "promote" an object from one class to another?
From: |
Marcus G. Daniels |
Subject: |
Re: Possible to "promote" an object from one class to another? |
Date: |
07 May 1999 08:59:19 -0700 |
>>>>> "PJ" == Paul Johnson <address@hidden> writes:
PJ> Is there an automagical way to say "aPrivate you are now of class
PJ> Sargent. Keep your IVars and take on the properties of this class
PJ> Sargent"?
Yes, this is possible by assigning to the class ivar in an instance¹.
There's a macro in Swarm called setClass to do this.
¹: This is strictly an Objective C (or Lisp) thing.
Languages like Java will require instantiation of a new object.
Here's an example:
#import <simtools.h> // initSwarmBatch
#import <objectbase/SwarmObject.h>
@interface Private: SwarmObject
- shoot;
- run;
- duck;
@end
@interface Sargent: Private
- order;
@end
@implementation Private
- shoot
{
printf ("[%s] Shoot!\n", [self getName]);
return self;
}
- run
{
printf ("[%s] Run\n", [self getName]);
return self;
}
- duck
{
printf ("[%s] Duck\n", [self getName]);
return self;
}
@end
@implementation Sargent
- order
{
printf ("[%s] Do it!\n", [self getName]);
return self;
}
@end
int
main (int argc, const char **argv)
{
id soldier;
initSwarmBatch (argc, argv);
soldier = [Private create: globalZone];
[soldier run];
setClass (soldier, [Sargent self]);
[soldier run];
[soldier order];
exit (0);
}
/*
Local Variables:
compile-command: "/opt/src/mgd/packages/development/egcs/bin/gcc -o hindu -g
-Wno-import -L/opt/SUNWtcl/8.0/sun4/lib -R/opt/SUNWtcl/8.0/sun4/lib
-L/opt/SDGblt/2.4g/lib -R/opt/SDGblt/2.4g/lib -L/opt/SDGlibffi/1.20/lib
-R/opt/SDGlibffi/1.20/lib -L/opt/src/mgd/packages/swarm/swarm/lib
-R/opt/src/mgd/packages/swarm/swarm/lib
-L/opt/src/mgd/packages/development/zlib/lib
-R/opt/src/mgd/packages/development/zlib/lib -L/usr/local/X11/lib
-R/usr/local/X11/lib -L/usr/openwin/lib -R/usr/openwin/lib
-L/opt/SDGhdf5/1.0.1/lib -I/opt/src/mgd/packages/swarm/swarm/include hindu.m
-ljavaswarm -ljavaswarmstubs -lanalysis -lspace -lsimtools -lsimtoolsgui
-lactivity -ltkobjc -lrandom -lobjectbase -ldefobj -lcollections -lmisc
-ltclobjc -ltk8.0 -ltcl8.0 -lBLT -lsocket -ldl -lnsl -L/usr/openwin/lib -lhdf5
-lpng -lz -lXpm -lX11 -lffi -lm -lobjc -lpthread -lposix4"
End:
*/
==================================
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.