[Lazarus] global items in TApplication

Marc Santhoff M.Santhoff at web.de
Sun Sep 15 16:20:25 CEST 2013


On So, 2013-09-15 at 10:36 +0100, Graeme Geldenhuys wrote:
> On 2013-09-15 04:22, Marc Santhoff wrote:
> > How do you handle this?
> > How can I meet the spec and put all global into the .dpr-file?
> 
> 
> I use the Singleton design pattern for the solution. I often create a
> Application Class (nothing to do with TApplication) that keeps track of
> such things like global user preference, lookup lists etc.
> 
> If other units require references I refactor my class structure so I
> have some base class I can pass in to other units. Those units then
> reference the passed in instance, and never the original application
> class (and related unit) directly. This is called Dependency Injection -
> yet another software design pattern that removes hard-coded dependencies.
> 
> 
> Design Patterns are your friend! ;-)

It's not in question how to implement global objects. Some are
singletons by design and others are not in code but work like they were,
because the only place the constructor is (allowed to be) called is the
inittialization section.

The qeustion is where to store those objects.

-- 
Marc Santhoff <M.Santhoff at web.de>





More information about the Lazarus mailing list