'Once' properties.

Carl Banks pavlovevidence at gmail.com
Tue Oct 6 08:07:36 CEST 2009


On Oct 5, 7:56 pm, menomnon <p... at well.com> wrote:
> Does python have a ‘once’ (per class) feature?
>
> ‘Once’, as I’ve know it is in Eiffel.  May be in Java don’t.
>
> The first time you instantiate a given class into an object it
> constructs, say, a dictionary containing static information.  In my
> case static is information that may change once a week at the most and
> there’s no need to be refreshing this data during a single running of
> the program (currently maybe 30 minutes).
>
> So you instantiate the same class into a second object, but instead of
> going to the databases again and recreating the same dictionary a
> second time, you get a pointer or reference to the one already created
> in the first object – copies into the second object that is.  And the
> dictionary, no matter how many instances of the object you make, is
> always the same one from the first object.
>
> So, as we put it, once per class and not object.
>
> Saves on both time and space.

Sounds like Borg Pattern:

http://code.activestate.com/recipes/66531/


Carl Banks



More information about the Python-list mailing list