Re: objects and "global / shared data"
Re: objects and "global / shared data"
- Subject: Re: objects and "global / shared data"
- From: Abhinav K Tyagi <email@hidden>
- Date: Thu, 05 May 2011 22:21:20 +0530
Hi,
A singleton can be a good option for your shared data as suggested by
many people over here.
However, if you dont want a singleton, you can setup the Application
delegate as the data holder.
since application object can be accessed from anywhere in the app, you
can thus access your Array
as you said.
The advantage of making singleton "MODEL" will be that MVC approach
will be clear and your model will
be a seperate stuff in case you need to extend the data source from a
simple array.
please correct me if any problem with approach of a ivar in delegate
Abhinav
On May 4, 2011, at 3:38 AM, Martin Batholdy wrote:
Hi,
I am still new to objective-c and cocoa and the whole object-
oriented approach.
So perhaps this is a weird question for you, but for me it is really
important to understand.
I have a small program with a DataHandler-class.
This class has methods to get data from a file on the disk and to
save it.
Actually it reads a plist containing an Array.
Now I need this Array at different places in my program.
I want to display it in a menu and in a tableView.
But the menu is created in a different class than the one managing
the tableview.
However both classes need the data from the DataHandler.
So they separately initiate their own instance of DataHandler.
Now the problem is that when one class changes something in the
array the other class doesn't know about that,
because it has its own instance of the DataHandler.
Now how can I make sure that a global data-source is available
independent from instances and their state?
How can I share data between objects?
I read something about singletons and that by declaring the
DataHandler object a singleton I can make sure that over the whole
program only one DataHandler-instance is initiated,
and the actual Data-Array is the same in each instance.
But I also read that singletons are bad practice.
But how can I share data (an Array) over different objects?
I still don't get this point ...
Or do I have to use CoreData?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Thanks
Abhinav K Tyagi
email@hidden
---------------------------------------------------------------
* Composed using Mac Mail. Please report inconsistencies if any.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden