How to organize code for conversion between different classes? (avoiding cyclic dependencies)

Stephen Hansen apt.shansen at gmail.com
Thu Oct 15 18:59:00 CEST 2009


On Thu, Oct 15, 2009 at 8:02 AM, Peng Yu <pengyu.ut at gmail.com> wrote:

> Suppose I have classes 'A',  'B',  'C',  'D'. The definition of these
> classes are long enough so that I have to put each class in a separate
> module 'mA', 'mB', 'mC', 'mD', which are in packages 'pA', 'pB', 'pC',
> 'pD', respectively. And there were no need to have conversion
> functions between these classes.
>
> As my program evolves, I need to have a conversion function between
> any pair of classes. I could define the conversion functions as member
> methods like the following. But if I do this for the classes B, C, D,
> I would end up with cyclic dependencies, which should be avoid.
>

[..]

Another choice is that I can put the conversion functions in some
> modules and import 'mA', 'mB', 'mC', 'mD' when needed. However, since
> mA, mB, mC, mD are in different packages, I'm not sure where to put
> the new modules that have the conversion functions.
>
>
I'd do it this way, as for where? Obviously above pA, pB, pC and pD. Either
in a package those packages are all in, or in just a top-level code
directory if that's how you're organized.

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091015/39f6f681/attachment.html>


More information about the Python-list mailing list