Re: Using instance of Protocols across application layer files
Re: Using instance of Protocols across application layer files
- Subject: Re: Using instance of Protocols across application layer files
- From: Chris Hanson <email@hidden>
- Date: Fri, 26 Dec 2003 11:07:40 -0600
On Dec 26, 2003, at 6:56 AM, Ramakrishna Kondapalli wrote:
In short, I need to know, how can we use the instance of a protocol
across the application level files by hiding the actual communication
mechanism (JNI/SOAP).
Don't.
Objective-C isn't Java, and you shouldn't be using the same design
patterns in an Objective-C Cocoa application that you'd use in a Java
J2EE application. (In fact, I wouldn't even use those design patterns
in any other type of Java application; they're very verbose and don't
buy you much.)
You want to abstract away the communication mechanism. Your best bet,
then is to have some sort of endpoint class on which communication
happens:
@interface MyEndpoint : NSObject
{
}
+ (MyEndpoint *)endpointForProtocol:(int)protocol; // JNI or SOAP
- (void)doSomething;
- (void)doSomethingElse;
@end
This is a base class that defines everything generic in your system.
You'll then have two subclasses, JNIEndpoint and SOAPEndpoint, that can
be instantiated and returned by its +endpointForProtocol: class method.
In short, in Objective-C you don't use a whole ton of factory classes
implementing factory interfaces to do this kind of thing. Instead you
use inheritance and class methods.
Oh, one other thing: Don't use method names in Objective-C that start
with "get," particularly as class methods. Accessor methods follow a
very specific naming convention; "get" methods in Cocoa retrieve values
into user-supplied buffers. (For example, -[NSData getBytes:] and
-[NSString getCharacters:].)
Learn and follow the naming conventions and design patterns used by
Cocoa, they were established for a reason. Don't just transliterate
from Java to Objective-C. You won't get good results that way.
-- Chris
--
Chris Hanson <email@hidden>
bDistributed.com, Inc.
Outsourcing Vendor Evaluation
Custom Mac OS X Development
Cocoa Developer Training
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.