• 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: Simon Stapleton <email@hidden>
  • Date: Mon, 10 Dec 2001 19:57:27 +0000

From: Riccardo Santato <email@hidden>
To: Cocoa dev <email@hidden>
Subject: Re: Damn sisters :-)
Date: Mon, 10 Dec 2001 19:11:47 +0100

You are not supposed to have access to another class's data. Create
accessor methods to access the data. For instance,
- (id)myInstanceVariable
{
return myInstanceVariable;
}

I've already thought about this option but I supposed I was rather stupid
to use a "dummy" function just to pass a variable... I hoped there was a
cleaner way :-))

That _is_ the clean way. If you only learn one thing this week, learn that.

Accessor methods provide the interface to your class. This means you _never_ need to care about the implementation. Even internally.

_ALWAYS_ use accessors. Ever wondered why you can't see the internal variables of the Cocoa classes? You don't need to see them. Ever. No, not even once. Except in accessors and mutators (and _possibly_ in constructors and destructors for performance reasons when using C++).

The word is 'Encapsulation'.

And, in response to the title of the thread, you never, ever, ever, ever need to directly access the internal variables of another class. To need to do so is the most abhorrent design flaw, and you should go back to the drawing board. Tight coupling of this sort is bad. Really bad. Think what happens if someone poses as one of your classes...

Simon (slightly drunk, and looking at the fact his own source doesn't do what he suggests ;-)

--
PGP Key Id : 0x50D0698D
--
Your mouse has moved. You must restart Windows NT for this change to be recognised.


  • Prev by Date: Re: How to get scripting to work without NSApplication
  • Next by Date: Disable a menu (item)
  • Previous by thread: Re: Damn sisters :-)
  • Next by thread: Re: Damn sisters :-)
  • Index(es):
    • Date
    • Thread