• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Damn sisters :-)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Damn sisters :-)


  • Subject: Re: Damn sisters :-)
  • From: Brian Luft <email@hidden>
  • Date: Mon, 10 Dec 2001 15:52:31 -0600

On 12/10/01 3:17 PM, "Ondra Cada" <email@hidden> wrote:
>>>>>>> Riccardo Santato (RS) wrote at Mon, 10 Dec 2001 19:11:47 +0100:
> RS> >You are not supposed to have access to another class's data. Create
> RS> >accessor methods to access the data. For instance,
> RS> >- (id)myInstanceVariable
> RS> >{
> RS> >return myInstanceVariable;
> RS> >}
> RS>
> RS> I've already thought about this option but I supposed I was rather stupid
> RS> to use a "dummy" function just to pass a variable... I hoped there was a
> RS> cleaner way :-))
>
> This is actually the very cleanest one, for the excellent reason that you
> are free the next year or so to change the implementation so that this will
> look like, say
>
> - (id)myInstanceVariable {
> return [[myInstanceVariableStorage objectForKey:@"oldInstances]
> objectAtIndex:3];
> }
>
> without breaking backward compatibility the slightest bit. It's one of the
> more powerful and nicest OO things ;)

This is totally unrelated to the topic at hand, but one of the really cool
things about C# (no Microsoft flames, please :P) that I wish Objective-C had
are properties. They let you simulate normal member variables but actually
call accessor and set functions.
For instance, you can have a String myStr property that actually sets
something in a dictionary in its implementation, like in Ondra's example,
transparently. This lets the user do simply:
MyClass.myStr = "Blah"
String myLocalStr = MyClass.myStr;
And both will not set the variable directly but will instead call the
associated get or set function. Pretty neato, if you ask me ;)

Thanks. Brian


  • Follow-Ups:
    • RE: Damn sisters :-)
      • From: "Dave MacLachlan" <email@hidden>
    • Re: Damn sisters :-)
      • From: Brian Hill <email@hidden>
    • Re: Damn sisters :-)
      • From: Ondra Cada <email@hidden>
    • Re: Damn sisters :-)
      • From: "David W. Halliday" <email@hidden>
References: 
 >Re: Damn sisters :-) (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: logout and auto-login
  • Next by Date: Re: Cocoa & signal handlers
  • Previous by thread: Re: Damn sisters :-)
  • Next by thread: Re: Damn sisters :-)
  • Index(es):
    • Date
    • Thread