Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15536 > unrolled thread

Re: The python implementation of the "relationships between classes".

Started byChris Angelico <rosuav@gmail.com>
First post2011-11-11 00:26 +1100
Last post2011-11-11 00:26 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: The python implementation of the "relationships between classes". Chris Angelico <rosuav@gmail.com> - 2011-11-11 00:26 +1100

#15536 — Re: The python implementation of the "relationships between classes".

FromChris Angelico <rosuav@gmail.com>
Date2011-11-11 00:26 +1100
SubjectRe: The python implementation of the "relationships between classes".
Message-ID<mailman.2595.1320931600.27778.python-list@python.org>
On Fri, Nov 11, 2011 at 12:15 AM, Jerry Zhang <jerry.scofield@gmail.com> wrote:
> For example, in composition model, the container object may be responsible
> for the handling of embedded objects' lifecycle. What is the python pattern
> of such implementation?

Here's an example:

class Test(object):
  def __init__(self):
    self.lst=[1,2,3]
    self.map={"foo":12,"bar":34}

This is a container that has a list and a dictionary in it. When an
instance of the container is destroyed, its list and dictionary will
be destroyed too (assuming nobody's made other references to them).
You don't need to code anything explicitly for that.

Chris Angelico

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web