looking for design pattern name

Andrew Dalke adalke at mindspring.com
Sun Jul 27 19:10:33 EDT 2003


I'm looking for the name used for a pattern like what Qt uses for
it's container hierarchy.  I'm doing this design for molecules, so I'll
use that as my example.

There's a container, in this case, a Molecule.  A Molecule has Atoms
and Bonds.  When an Atom, it is passed the parent container as
part of the constructor, as in

mol = Molecule()
O1 = Atom(mol, 8)    # note the parent in the constructor
O2 = Atom(mol, 8)
Bond(O1, O2, 2)    # (the parent is implicit - comes from the atoms)

I want to compare this to a design like

mol = Molecule()
O1 = mol.add_atom(8)
O2 = mol.add_atom(8)
mol.add_bond(O1, O2)

which does not allow a user-derived Atom and Bond class

and one like

mol = Molecule()
O1 = Atom(8)
mol.add_atom(O1)
O2 = Atom(8)
mol.add_atom(O2)
b = Bond(2)
mol.add_bond(b)

which allows user-defined types but which has a more
complicated ownership pattern (eg, you can have atoms and
bonds which aren't contents of a Molecule).

Anyone have good names for any of these three styles?

Thanks!

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list