[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Protocol questions
From: |
Marcus G. Daniels |
Subject: |
Re: Protocol questions |
Date: |
07 Apr 2000 09:26:27 -0700 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
>>>>> "PJ" == Paul Johnson <address@hidden> writes:
PJ> - (int)doThis
PJ> {
PJ> [self subclassResponsibility: @selector(doThis)];
PJ> return ???????;
PJ> }
Say, zero.
PJ> 2. In the Recruiter class, many methods are implemented. Some
PJ> methods are added in typeA that are not in typeB. When I have a
PJ> typeA object, I want to use those methods, but programs won't
PJ> compile. The compiler says the method is not in the protocol. I
PJ> have to add these methods to the protocol to get the compiler to
PJ> work.
#import <simtools.h> // initSwarmBatch
#import <defobj/Create.h> // CreateDrop
@protocol BaseProtocol
- (void)method1;
@end
@protocol ProtocolA
- (void)method2;
@end
@protocol CompositeProtocol <BaseProtocol, ProtocolA>
@end
@interface ClassA: CreateDrop <BaseProtocol>
- (void)method1;
@end
@interface ClassB: ClassA <CompositeProtocol>
- (void)method2;
@end
@implementation ClassA
- (void)method1
{
printf ("%s, Method 1\n", [self getName]);
}
@end
@implementation ClassB
- (void)method2
{
printf ("%s, Method 2\n", [self getName]);
}
@end
int
main (int argc, const char **argv)
{
initSwarmBatch (argc, argv);
{
id <BaseProtocol> a = [ClassA create: globalZone];
id <CompositeProtocol> b = [ClassB create: globalZone];
[a method1];
[b method1];
[b method2];
printf ("[a conformsTo: @protocol (BaseProtocol)]: %u\n",
(unsigned) [(id) a conformsTo: @protocol (BaseProtocol)]);
printf ("[a conformsTo: @protocol (CompositeProtocol)]: %u\n",
(unsigned) [(id) a conformsTo: @protocol (CompositeProtocol)]);
printf ("[b conformsTo: @protocol (BaseProtocol)]: %u\n",
(unsigned) [(id) b conformsTo: @protocol (BaseProtocol)]);
printf ("[b conformsTo: @protocol (CompositeProtocol)]: %u\n",
(unsigned) [(id) b conformsTo: @protocol (CompositeProtocol)]);
}
return 0;
}
/*
Local Variables:
compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc
-DAPPNAME=protocolTest -Wall -Wno-protocol -o protocolTest -g -Wno-import
-I$SWARMHOME/include/swarm -L$SWARMHOME/lib/swarm protocolTest.m -lswarm -lobjc"
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.