I actually tried doing that- encompassing the data inside its own
object. But the problem I'm having involves how to get the data when I
need it.
I have a controller object that does much of the processing and
coordinating for the program, its much of the 'guts' of the simple
program, and it is also responsible for init'ing the single instance
of this data object.
That's fine and dandy- the controller can then access the integers via
the data object's accessor methods. The problem is that I have a
custom NSView (among other things) that needs to also access this
data. Since the controller creates the instance of the data object,
it's the only object that has a reference pointing to the data object,
so any other classes doesn't know how to find the data object to
request the integers. I suppose I could create a method in the
controller that would allow me to do this:
int x;
x = [[myController ] giveMeTheXInteger];
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.
Maybe I'm just not understanding how this works, I apologize, I'm a
newbie. I'm not fully understanding how all these objects are supposed
to find each other. C seems like an efficient language, I
can't believe I would have to create an instance variable in every
single class just to point to this data object will I? Thank you
for your feedback, any additional help in explaining this will be
greatly appreciated.
-matt
12/27/05, j o a r <joar (AT) joar (DOT) comwrote:
27 dec 2005, at 11.55, Matt Reagan wrote:
I understand that in P it's generally said to be a bad idea to use
'global' variables outside the normal object-oriented methodology
but can anyone please advise me on the best way to make a very small
array of integers available to my entire application? I have a main
controller object that had this:
@public
int myIntArray[10];
But despite the public command, I can't seem to access it from another
class. I made sure to include the controller's header file where it's
needed.
What's the easiest way to make some integers available to the whole
application?
Easiest or best?
In P you have objects, not free floating data. holds data,
and methods that acts on their data. So, who is the "owner" of your
int array? You can probably build a class to hold that data, in which
case you would allow access to that data via methods on that class:
@class MyIntArray : NS
{
@private
int myIntArray[10];
}
- (int) intAtIndex:(int) index;
- (void) setInt:(int) integer atIndex:(int) index
@end
You might want to consider implementing this class as a singleton class.
j o a r
>
>
>
>
>
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
Help/Unsubscribe/Update your Subscription:
%40developershed.com
This email sent to bsdarchive (AT) developershed (DOT) com