I have a
Class::DBI base class and some classes that inherit from it. In the base class, I need to set up the database connection. However, I want to keep these classes independent of the actual method of finding that config data.
In the Java world, people usually solve this by using a directory service to look up the config parameters, or by using the "Inversion of Control" or "Dependency Injection" design patterns. The latter involves having some sort of server code which looks at some config files and goes through setting certain parameters on specified objects. For example, it could set a config object in my Class::DBI base class at startup. I've had a brief look at IOC::Lite, but it looks unfinished and I'm not sure it will work for this.
The bottom line is that I have some code which I want to make reusable that has a dependency on something which can vary by project. There are a number of ways to solve this, but most of them feel like overkill (a config file that tells where my config file is?). So I'm asking, what do others do in this situation?
UPDATE: Fixed wording about inheritance as noted by japhy
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.