[nycphp-talk] Accessing a method from one class in another
Kenneth Downs
ken at secdat.com
Wed Jan 18 14:01:27 EST 2006
> On 1/18/06, Kenneth Downs <ken at secdat.com> wrote:
>> >
>> > I guess my options are:
>> >
>> > - set a global variable, which has to be passed to each method
>>
>> By the KISS principle, this is the simplest and is also effective.
>> Therefore any more complicated solution would have to be defended, no?
>
> Not always.
Always.
Involving two completely different connection systems, your own and
PEAR's, is not a trivial design decision, either for you or for that
unnamed person who will code after you. The number one mistake that
programmers make is abstracting against cases that *might* happen but
which are not on the table right now. There is a huge difference between
a clean elegant design that is simple and *extensible* and a clunky ugly
horrible design that tries to account for everything that might ever
happen anywhere.
In any event, if you go to a two-connection system then by the KISS
principle you want to find the simplest possible solution for that
context.
Going to a two-connection system is itself rather questionable under the
KISS principle, if you are that worried about it perhaps we should use
PEAR to start off?
> For a very simple app, maybe... but let's say you start
> using a php-based library, say, something PEAR or otherwise, that also
> uses a db connection (or other common object/var that needs wide
> access), that also uses a global called $db, or $dbh, or $file, or...
> This kind of bug can be subtle and hard to track down, particularly if
> the person maintaining the code is no longer the person who wrote it.
>
> Also, using a singleton with a static accessor allows checks to be
> implemented once. The example functions show that you can check for a
> null object in one place; implementing other checks/code in there is
> also possible.
>
> -Chris
> _______________________________________________
> New York PHP Community Talk Mailing List
> Show Your Participation
> http://www.nyphp.org/show_participation.php
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
>
--
Kenneth Downs
Secure Data Software
631-379-0010
ken at secdat.com
PO Box 708
East Setauket, NY 11733
More information about the talk
mailing list