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


Groups > comp.lang.python > #15536

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

References <CANVwdDr-6x8bt4iNL+Q=jZ7+edk7XbR2K_LeJC3Z60qy=vVFQA@mail.gmail.com>
Date 2011-11-11 00:26 +1100
Subject Re: The python implementation of the "relationships between classes".
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2595.1320931600.27778.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web