Re: Global variables?
Re: Global variables?
- Subject: Re: Global variables?
- From: j o a r <email@hidden>
- Date: Tue, 27 Dec 2005 12:52:07 +0100
On 27 dec 2005, at 12.42, Matt Reagan wrote:
But this roundabout way of referencing the controller, which
references the data object, which then returns its integer, seems
really silly.... it's just an integer. I just need multiple classes to
be able to modify and access it.
I don't think it's silly at all - data hiding is at the core of OOP,
and object graphs and object relationships are part of this.
That said, there are times when you want to provide public access to
some methods / objects, and that's why I mentioned the singleton
pattern in my original reply. You should read up on it, there's
documentation on that design pattern in Apple's documentation, in the
list archives and most Cocoa / ObjC books you could find. It relies
on using a class method to access a shared instance - so anyone who
has #imported the header file from that class can reference the
shared instance, and it's methods.
An alternative is of course to simply use class methods and a static
variable, and not bother with the creating the shared instance at
all. Personally I prefer to use singleton classes though, as they
allow you to stick to the regular ObjC design & memory management
patterns - less room for errors that way.
j o a r
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden