Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C 2.0 style question.



Why not trying to made a real difference between accessors and properties ?

what about :
accessors for algorithms informations ( how the algorithm works )
properties for user informations  (what kind of information a user can have access using a instance)

i want to say that because we can see too much example in coding :

-(NSString *)myString // public information
{
return myString; // private variable
}

don't you think you loose time and clarity by repeating altime the same kind of information ??

why not trying :

-(NSString *)stringWithFormat
{
... //concatenate differend kind of private information
... // and change some of them by their equivalent : keyLogIn --->UserID

return thestringFormatted; //becomes public
}


Le 22 avr. 08 à 22:52, Sherm Pendley a écrit :

On Mon, Apr 21, 2008 at 4:27 PM, Scott Andrew <email@hidden> wrote:
I have a question.

I am getting ready to teach a bit on Objective-C 2.0 to colleagues and I have a bit of a style question.

If i have the following defined:

@interface foo : NSObject
{
@private
NSString* myString;
}

@property(copy) myString;

-(void)displayString;


@end

Which way is better to use myString in the displayString function? Is it better to do self.myString or use myString directly. 

Comming from a C++ part of me says to always use the acessors if defined (unless private and not exposed), also using the accessors allows us to make sure our bindings are updated if its a bound value, but i see a mix of code and it may depend on if the iVar is to be exposed or not.. The company i work for is now getting into iPhone and 10.5 development and i want to stress the proper design choices.

Word has it that the iPhone doesn't use GC. So, without accessors you're going to end up with memory management scattered throughout your class, wherever you assign a new value to the instance variable. Using properly-written accessors throughout is a good way to ensure that you've covered 99% of your memory management concerns. I'd call that a question of sanity, not one of style. :-)

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/objc-language/email@hidden

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/objc-language/email@hidden

This email sent to email@hidden

References: 
 >Objective-C 2.0 style question. (From: Scott Andrew <email@hidden>)
 >Re: Objective-C 2.0 style question. (From: "Sherm Pendley" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.