[Biococoa-dev] mass calculator bug
Alexander Griekspoor
mek at mekentosj.com
Sun Aug 29 16:02:43 EDT 2004
>> Of course you note one problem here, we haven't implemented a number
>> of accessors. I already mentioned once that we should for all
>> variables like Apple advices us to do, and always call the accessors
>> if you want to change things (instead of directly accessing the
>> variable). This is one example where this comes in handy. If we don't
>> want to make some accessors public, we have to @private them so
>> they're invisible outside the class.
>
> Yes, I fully agree. What's the syntax again to use @private?
From Objc.pdf
@private The instance variable is accessible only within the class
that declares it.
@protected The instance variable is accessible within the class that
declares it and within classes that inherit it.
@public The instance variable is accessible everywhere.
Example header file:
@interface Worker : NSObject {
char *name;
@private
int age;
char *evaluation;
@protected
id job;
float wage;
@public
id boss;
}
By default, all unmarked instance variables (like name above) are
@protected.
This is for instance variables. For methods making them "private" is
pretty easy, leave the declaration out of the header file and put it in
the .m file before you begin the @implementation:
Example Prefcontroller.m:
#import "PrefController.h"
@interface PrefController (Private)
NSView * currentPane;
id delegate;
-(void)setupToolbar;
@end
@implementation PrefController
// ================================================================
#pragma mark --- INIT & DEALLOC
// ================================================================
- (PrefController*)init
{
self = [super initWithWindowNibName:@"Preferences"];
etc...
This way the currenPane variable and the setupToolbar are available
within the class, but nobody outside it can see it as they are not
declared in the (public) header file.
>> Anyway, I leave this up to you guys. An alternative would be a
>> special init method that takes all variables as input and do
>> everything in one call.
>>
>
> I don't like that idea, I prefer the accessors.
Me too to be honest ;-)
*********************************************************
** Alexander Griekspoor **
*********************************************************
The Netherlands Cancer Institute
Department of Tumorbiology (H4)
Plesmanlaan 121, 1066 CX, Amsterdam
Tel: + 31 20 - 512 2023
Fax: + 31 20 - 512 2029
AIM: mekentosj at mac.com
E-mail: a.griekspoor at nki.nl
Web: http://www.mekentosj.com
LabAssistant - Get your life organized!
http://www.mekentosj.com/labassistant
*********************************************************
More information about the Biococoa-dev
mailing list