Re: Followup - Re: Is there a pattern for creating an object with global scope?

2013-04-15 Thread Uli Kusterer
On 15.04.2013, at 12:44, Tom Davie wrote: > Note also – simply using your app delegate as a store for things that aren't > singletons, but only one of them is pointed at by your app delegate is also > horrific – you're just substituting one singleton for another. If it were only that! At least

Re: Followup - Re: Is there a pattern for creating an object with global scope?

2013-04-15 Thread Graham Cox
On 16/04/2013, at 10:18 AM, Graham Cox wrote: > I don't know what you mean by "dependency injection", it's not a term I've > heard of OK, I looked it up. I hadn't heard the term but I'm very familiar with the concept it refers to. Sometimes the service or dependent entity should be a singl

Re: Followup - Re: Is there a pattern for creating an object with global scope?

2013-04-15 Thread Graham Cox
On 15/04/2013, at 8:44 PM, Tom Davie wrote: > Wow, I really can't get my head around this one. You make bold statements > like "GLOBALS ARE BAD NEWS" (which I 100% agree with), but then follow up > with effectively "use singletons instead". Singletons bring with them 95% of > the problems g

Re: Followup - Re: Is there a pattern for creating an object with global scope?

2013-04-15 Thread Tom Davie
On 15 Apr 2013, at 00:25, Graham Cox wrote: > > On 14/04/2013, at 2:08 PM, YT wrote: > >> My struggle is partially due to my lack of experience in OOP. I just have >> not written enough OO code as of yet. AND I'm very new to Objective-C. >> Hence my lack of experience and working knowledge

Re: Followup - Re: Is there a pattern for creating an object with global scope?

2013-04-14 Thread Graham Cox
On 14/04/2013, at 2:08 PM, YT wrote: > My struggle is partially due to my lack of experience in OOP. I just have not > written enough OO code as of yet. AND I'm very new to Objective-C. Hence my > lack of experience and working knowledge of Objective-C. > > extern int gFoobar; > > I underst

Re: Followup - Re: Is there a pattern for creating an object with global scope?

2013-04-14 Thread Uli Kusterer
On 14.04.2013, at 06:29, Steve Mills wrote: > Oh, that's easy, once you know how to make singletons. OK, I wouldn't call it > easy, but it's the right thing to do. If the C++ Steve wrote helps you understand things better, here's a 1-to-1 translation of that code to the equivalent in Objective

Re: Is there a pattern for creating an object with global scope?

2013-04-14 Thread Scott Ribe
On Apr 13, 2013, at 9:51 PM, Jens Alfke wrote: > C++ static initializers are evil, though, at least the ones that run code. > They run super early, in an undefined order, with no way to specify > dependencies between them; so if you’re not careful they can slow down launch > and/or cause weird

Re: Is there a pattern for creating an object with global scope?

2013-04-13 Thread Jens Alfke
On Apr 13, 2013, at 10:02 PM, Allan Odgaard wrote: >> C++ static initializers are evil, though, at least the ones that run code. >> They run super early, in an undefined order, with no way to specify >> dependencies between them; so if you’re not careful they can slow down >> launch and/or ca

Re: Is there a pattern for creating an object with global scope?

2013-04-13 Thread Allan Odgaard
On Apr 14, 2013, at 10:51, Jens Alfke wrote: > C++ static initializers are evil, though, at least the ones that run code. > They run super early, in an undefined order, with no way to specify > dependencies between them; so if you’re not careful they can slow down launch > and/or cause weird n

Re: Followup - Re: Is there a pattern for creating an object with global scope?

2013-04-13 Thread Steve Mills
On Apr 13, 2013, at 23:08:41, YT wrote: > int gFoobar = 42; > > Then reference it elsewhere as: > > extern int gFoobar; > > I understand that solution and its working for me right now. I have a PreRun > Class that defines the object and I instantiate in main.m just before the > line > retu

Followup - Re: Is there a pattern for creating an object with global scope?

2013-04-13 Thread YT
First just to clear a distraction... I didn't want to actually create my own version of Preferences. In fact that was a mistake to even mention it. Sorry, I was flailing in my mind trying to describe what I was struggling with and out came Preferences as an example. Totally throw away the

Re: Is there a pattern for creating an object with global scope?

2013-04-13 Thread Jens Alfke
On Apr 13, 2013, at 6:38 AM, Scott Ribe wrote: >> YT wants to create an object, which isn’t as straightforward because you >> can’t have an object literal in Objective-C. Instead you declare a global >> pointer and initialize it early on. > > Oh, right, I work in Objective-C++, so I don't hav

Re: Is there a pattern for creating an object with global scope?

2013-04-13 Thread Scott Ribe
On Apr 12, 2013, at 10:08 PM, Jens Alfke wrote: > YT wants to create an object, which isn’t as straightforward because you > can’t have an object literal in Objective-C. Instead you declare a global > pointer and initialize it early on. Oh, right, I work in Objective-C++, so I don't have that l

Re: Is there a pattern for creating an object with global scope?

2013-04-13 Thread Tom Davie
On 13 Apr 2013, at 13:45, Uli Kusterer wrote: > On 13.04.2013, at 06:08, Jens Alfke wrote: >> On Apr 12, 2013, at 6:54 PM, Scott Ribe wrote: >> >>> Yes, extremely easy, just "create" the var, as in: >>> >>> int gFoobar = 42; >> >> YT wants to create an object, which isn’t as straightforward

Re: Is there a pattern for creating an object with global scope?

2013-04-13 Thread Uli Kusterer
On 13.04.2013, at 06:08, Jens Alfke wrote: > On Apr 12, 2013, at 6:54 PM, Scott Ribe wrote: > >> Yes, extremely easy, just "create" the var, as in: >> >> int gFoobar = 42; > > YT wants to create an object, which isn’t as straightforward because you > can’t have an object literal in Objective-

Re: Is there a pattern for creating an object with global scope?

2013-04-12 Thread Alex Zavatone
FYi, it's advice, not advise. Advice is what you give, advise is the giving of advice. But I like Matt Galloway's singleton approach for a class you can import and use everywhere. http://www.galloway.me.uk/tutorials/singleton-classes/ On Apr 12, 2013, at 9:30 PM, YT wrote: > Perhaps my appro

Re: Is there a pattern for creating an object with global scope?

2013-04-12 Thread Jens Alfke
On Apr 12, 2013, at 6:54 PM, Scott Ribe wrote: > Yes, extremely easy, just "create" the var, as in: > > int gFoobar = 42; YT wants to create an object, which isn’t as straightforward because you can’t have an object literal in Objective-C. Instead you declare a global pointer and initialize

Re: Is there a pattern for creating an object with global scope?

2013-04-12 Thread Scott Ribe
On Apr 12, 2013, at 7:30 PM, YT wrote: > Is this even possible? Yes, extremely easy, just "create" the var, as in: int gFoobar = 42; Then reference it elsewhere as: extern int gFoobar; ***NOW*** whether or not this is a good thing to do, particularly for your preferences, and also some detai

Re: Is there a pattern for creating an object with global scope?

2013-04-12 Thread Graham Cox
On 13/04/2013, at 11:30 AM, YT wrote: > Perhaps my approach is wrong. Looking for advise. > > So I'd like to define a Class called Preference. > > In main.m I'd like to create an object called myPreferences before the code > line > > return NSApplicationMain(argc, (const char**)); is run; >

Is there a pattern for creating an object with global scope?

2013-04-12 Thread YT
Perhaps my approach is wrong. Looking for advise. So I'd like to define a Class called Preference. In main.m I'd like to create an object called myPreferences before the code line return NSApplicationMain(argc, (const char**)); is run; I assume the object myPreferences will persist the life of