Reference to base namespace in a class.

D

David

Hi,
I'm working on a project where we're juggling with two potential
implementations.
In the two scenarios, we create objects in the base namespace. These
objects are interdependent, in the sense that to compute something,
they have to look up the value of the other objects (their parents).
The objects are functions, by the way, with some additional attributes.


In the first scenario, as the objects are created, they immediately
share references and can call each other's value. All these objects are
then referenced in a class that defines some methods accessing those
objects. The advantage is that you can call the functions from the base
namespace and they'll know where to look to make the computations. The
downsize is that if you delete one object by mistake, nothing works
anymore, that is, the methods from the class will no longer reference
the right objects.

In the second scenario, as the objects are created, they only know the
name of their parents, and don't have their actual reference. To
compute something, we have to pass the values of the other objects
explicitely. A class is then instantiated, where we look up the
__main__ dictionary for the names of the parents given by each
function, copy the objects inside the class, create an attribute for
each object on the fly and link the objects together using the parents
names. The advantage is that even if an object in the base namespace
is destroyed, the class methods will still work since the references
are all internal to the class instance. The disadvantage is that the
objects in the base namespace are dummy objects, ie they don't speak to
each other.

I guess it's hard to understand the context from this quick
description, but the code would look equally opaque.

Here is an attempt to put that into a simple question:

Are there counter indications to reference objects in the base
namespace from a class ?

Thanks for your help.

David Huard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,800
Messages
2,569,657
Members
45,416
Latest member
MyraTrotte
Top