I'm building a Librarian module -- it has a couple of methods for basic object creation, getting, setting and cleanup. These objects are actually used to access documents in a file system.

So far I have a new method that creates a new object with a supplied name if that name is available. If the name's not available, the new method fails.

I'm doing development by testing, so as I add more code I write tests, and continue when the tests pass. It's a very neat way to develop code, but now I want to add tests that try to access an object that already exists, and the current new method won't allow that -- so I've figured I want to write an init method that will also be a method constructor, but only for names that already exist.

Obviously there's some common functionality between the two methods .. I'm not concerned about that. But is there a usual and customary naming convention or approach to do this in Object Oriented Programming?

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds


In reply to Determining what new and init methods do by talexb

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.