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

2011-11-10 Thread Jerry Zhang
A general description of my issue. To my understand, python's feature such as "name-reference-object" and "garbage collection" system did some of work for you, it makes your life easier, but you still need to add your explicit application in your code. For example, Composition implementation: you

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

2011-11-10 Thread Jerry Zhang
2011/11/11 Chris Angelico > On Fri, Nov 11, 2011 at 10:14 AM, Chris Kaynor > wrote: > > Continuing this OT discussion, would it be a brain transplant, or a > > full body transplant? > > It's just a rebinding. You don't move the body, you just bind your > name to a new body. It's perfectly legal

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

2011-11-10 Thread Jerry Zhang
2011/11/11 Terry Reedy > On 11/10/2011 9:31 AM, Jerry Zhang wrote: > > Unfortunately there is a difference between composition and >>aggregation in my real word, and my application really care this >>since it is trying to simulate this real world model, so my system >>should track

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

2011-11-10 Thread Jerry Zhang
2011/11/11 Benjamin Kaplan > On Thu, Nov 10, 2011 at 1:06 PM, Jerry Zhang > wrote: > > > > > > I just did an example code to describe what i am looking for. > > > /**/ > > # ... > > > > class Head: >

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

2011-11-10 Thread Chris Angelico
On Fri, Nov 11, 2011 at 10:14 AM, Chris Kaynor wrote: > Continuing this OT discussion, would it be a brain transplant, or a > full body transplant? It's just a rebinding. You don't move the body, you just bind your name to a new body. It's perfectly legal to have two names bound to one body (cf D

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

2011-11-10 Thread Chris Kaynor
On Thu, Nov 10, 2011 at 2:48 PM, Steven D'Aprano wrote: > On Thu, 10 Nov 2011 14:38:58 -0500, Terry Reedy wrote: > >> I will point out that in the real world, dead donor transplants are >> based on the fact the parts of the body do NOT have to die when the >> composition does. I will not be surpri

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

2011-11-10 Thread Steven D'Aprano
On Thu, 10 Nov 2011 14:38:58 -0500, Terry Reedy wrote: > I will point out that in the real world, dead donor transplants are > based on the fact the parts of the body do NOT have to die when the > composition does. I will not be surprised if we someday see arm > transplants. And Guido's Time Mach

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

2011-11-10 Thread Ethan Furman
Benjamin Kaplan wrote: You're still misunderstanding Python's object model. del does NOT delete an object. It deletes a name. The only way for an object to be deleted is for it to be inaccessible (there are no references to it, or there are no reachable references to it). foo = object() bar = fo

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

2011-11-10 Thread Terry Reedy
On 11/10/2011 9:31 AM, Jerry Zhang wrote: Unfortunately there is a difference between composition and aggregation in my real word, and my application really care this since it is trying to simulate this real world model, so my system should track this difference accurately, other

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

2011-11-10 Thread Benjamin Kaplan
On Thu, Nov 10, 2011 at 1:06 PM, Jerry Zhang wrote: > > > I just did an example code to describe what i am looking for. > /**/ > # ... > > class Head: >     def __init__(self): >     self.size = 5 >

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

2011-11-10 Thread Jerry Zhang
2011/11/11 Christian Heimes > Am 10.11.2011 17:09, schrieb Tim Wintle: > >> Meanwhile, I have a ZODB running, which stores all the living > >> objects. > > > > The ZODB is append only and stores all objects. Deleting references to > > an object (which would causes deletion of standard python obje

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

2011-11-10 Thread Jerry Zhang
2011/11/11 Tim Wintle > On Thu, 2011-11-10 at 22:25 +0800, Jerry Zhang wrote: > > > > > > 2011/11/10 Chris Angelico > > On Fri, Nov 11, 2011 at 12:58 AM, Jerry Zhang > > wrote: > > > Cls_a: > > > def __init__(self): > > > self.at1 = 1 > >

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

2011-11-10 Thread Christian Heimes
Am 10.11.2011 17:09, schrieb Tim Wintle: >> Meanwhile, I have a ZODB running, which stores all the living >> objects. > > The ZODB is append only and stores all objects. Deleting references to > an object (which would causes deletion of standard python objects) won't > delete it from the zodb, it

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

2011-11-10 Thread Tim Wintle
On Thu, 2011-11-10 at 22:25 +0800, Jerry Zhang wrote: > > > 2011/11/10 Chris Angelico > On Fri, Nov 11, 2011 at 12:58 AM, Jerry Zhang > wrote: > > Cls_a: > > def __init__(self): > > self.at1 = 1 > > Cls_b: > > def __init__(

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

2011-11-10 Thread Jerry Zhang
2011/11/10 Jerry Zhang > > > 2011/11/10 Chris Angelico > >> On Fri, Nov 11, 2011 at 12:58 AM, Jerry Zhang >> wrote: >> > Cls_a: >> > def __init__(self): >> > self.at1 = 1 >> > Cls_b: >> > def __init__(self): >> > self.com1 = Cls_a() >> > def __del__(self): >> >

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

2011-11-10 Thread Jerry Zhang
2011/11/10 Chris Angelico > On Fri, Nov 11, 2011 at 12:58 AM, Jerry Zhang > wrote: > > Cls_a: > > def __init__(self): > > self.at1 = 1 > > Cls_b: > > def __init__(self): > > self.com1 = Cls_a() > > def __del__(self): > > del self.com1 > > Is it a right impleme

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

2011-11-10 Thread Chris Angelico
On Fri, Nov 11, 2011 at 12:58 AM, Jerry Zhang wrote: > Cls_a: >     def __init__(self): >         self.at1 = 1 > Cls_b: >     def __init__(self): >         self.com1 = Cls_a() >     def __del__(self): >         del self.com1 > Is it a right implementation for composition? Yes, except that you don

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

2011-11-10 Thread Jerry Zhang
Hi Chris, Firstly thanks for your quick reply. 1. Your code example gives a point, but i may not reach my question yet, maybe because i did not make myself understood yet. Here is a more detail example question. I have a classes sets described by UML, which could be refered as Cls_A, Cls_B, CLs_

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

2011-11-10 Thread Chris Angelico
On Fri, Nov 11, 2011 at 12:15 AM, Jerry Zhang 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):