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, otherwise the system may
    not work well.

    For example,
    a. the Cls_arm and Cls_body may be composition, but not aggregation.
    My app must ensure that " one arm instance only live with one body
    instance, if the body instance die, the arm instance must die.

Create the arm as a private member '_arm' of body and make sure that no method of body passes out a reference to the arm. (In Python, outside code can still grab a reference to the private attribute, but that is a coding bug.)

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.

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to