Newbie: question regarding references and class relationships

Rick Johnson rantingrickjohnson at gmail.com
Tue Jun 11 20:02:31 EDT 2013


On Monday, June 10, 2013 2:56:15 PM UTC-5, Ian wrote:
> [...]
> There are a couple of ways you might get this to work the way you
> want.  One is by adding as an extra layer a proxy object, which could
> be as simple as:
> class Proxy(object):
>     def __init__(self, ref):
>         self.ref = ref
> Instead of adding points to the model, add instances of Proxy that
> contain the points.  When adding points to the lines, add the same
> Proxy objects instead.  

Oh gawd just stop here! Are you joking? Are you playing coy? Are you attempting to confuse the lad? This type of complexity you suggest is what renders code bases unreadable and gives sloppy programmers "job security".

> Later, when you want to replace a point in the
> model, leave the Proxy in place but change the Point it contains by
> modifying the "ref" attribute.  Since the Line only directly
> references the Proxy, it must follow the same ref attribute to access
> the Point, and so in that way it will "see" the change.  The downsides
> to this approach are that you have to then use the Proxy objects all
> over the place and explicitly "dereference" them by using the ref
> attribute all over the place.

Teacher: "What is the worse thing since memory management?"
Jimmy Says: "ooh! ohh! i know!
Teacher: "Yes jimmy?"
Jimmy: "Superfluous memory management?"
Teacher: "Oh no, I'm sorry Jimmy, you're so close but i was looking for: `Superfluous memory management by proxy`!"




More information about the Python-list mailing list