Re: Global variables

From: H. S. Lahman (h.lahman_at_verizon.net)
Date: 10/28/04


Date: Thu, 28 Oct 2004 17:00:37 GMT

Responding to ShadowMan...

> I frequently need to 'configure' my application with a lot of parameter
> (generally from external file), that need to be shared in the application.

That is a Good Thing. Parametric polymorphism is a very powerful tool
for abstracting invariants in the code while relegating detailed
differences to external data. That generally simplifies the code,
improves reliability, and makes maintenance easier.

> For example, I need SMTP server info when I neet to send emails from
> applications; max number of retrieved records, when I use search functions,
> and so on...
> In most cases, I use one (or more) Singleton that is pre-loaded on startup
> so it is accessible from everywhere.
> I know this is not the right approach, so what should be the best approach?!
> For example, if I don't permit EmailSender get smtp_server_info directly
> from a ConfigurationSingleton because in this way I create a strong bound,
> but I pass them as parameters...the the Client using EmailSender needs
> however to be aware of them....and so on...who should be the responsible for
> that?!

I think using Singleton may be a different issue. One employs the
Singleton design pattern when the problem requires a single instance of
a class but (a) there are multiple contexts where it can be created or
(b) the behavior doing the creating may be invoked multiple times. IOW,
there are multiple /opportunities/ to create the class instance and you
need to make sure only one is created. Singleton provides the
infrastructure for ensuring that.

That does not seem to be the case here since you pre-load it at startup.
  In that case there aren't multiple opportunities for creating it; just
the one at startup. So you can simply create one instance of the
subject class without all the infrastructure of the Singleton design
pattern.

However, you concerns seem to be more general, about the way to access
data from the SMTP server while isolating that access from the
processing context for sending emails. Without more details about what
you are doing, I can't speculate on specific approaches. For example,
the approach would probably depend upon whether you are processing
multiple emails at once or not. Could you provide a brief description
of the relevant (to the sending email context) objects you have already
identified and how you see them interacting (just a sentence of two
about each)? That is, I would like to understand your processing around
sending emails before I speculate on where to glue the SMTP server
access into that solution.

>
> (sorry for my english ;-) )

Not a problem so far.

*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl@pathfindermda.com
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
blog (under constr): http://pathfinderpeople.blogs.com/hslahman
(888)-OOA-PATH



Relevant Pages

  • Re: Utility classes?
    ... I don't want to duplicate code in multiple places. ... > (singleton) classes created to encapsulate related operations in one class. ...
    (comp.lang.cpp)
  • Re: Singleton Pattern
    ... one should /only/ use Singleton when the problem solution has multiple paths that could lead to violating the problem space referential integrity requirement in. ...
    (comp.object)
  • Re: Thread-safe Collection
    ... but after that it would only be supporting multiple readers. ... I wanted the dictionary items in a common memory store (to avoid ... If you pin a singleton somewhere, ... If you want to have fast parallel reads from multiple STAs, ...
    (microsoft.public.vb.com)
  • Re: Static Methods in DAO
    ... methods, or a single shared object (i.e. singleton), how can multiple ... code in a method at the exact same time if there is one shared object ...
    (comp.lang.java.programmer)