Hi! I'm having a hard time refactoring some modules which have cyclical dependencies. Example:
package Aa; use Bb; my $object = Bb->new();
and
package Bb; use Aa; my $object = Aa->new();
Obviously, bad arhitecture, but a lot of other things depend on these, so I wasn't sure how can I solve these things. I know this is not entirely related to Perl, it has more to do with programming theory, but I thought Perl has some specific things regarding this, like how could I use some design pattern, if there is one for these situations. There are some other kinds of cyclical dependencies too, like
package Aa; use Bb; my $result = Bb::some_function_which_does_not_create_object();
and
package Bb; use Aa; my $object = Aa::some_function_which_does_not_create_object();
These can be broken sometimes by taking out one modules functionality and putting it into another module (class) and then each of the 2 modules can use this new one, breaking the cycle, but this solution is not working all the times either. Could any one help me towards this? Thanks in advance, faceless.

In reply to Trying to break cyclical dependencies in Perl modules by faceless

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.