At 05:36 AM 8/15/01 -0700, Blair Burns wrote:
>Hi *,
>
>I am rather a beginner to Perl (and programming) but
>am nevertheless faced with maintaining a complex OO
>environment. Yikes! Anyway, here is my problem: I have
>two classes whose constructors return a db handle. "A"
>accepts parameters for user/password, while "B",
>although it uses A to connect as well, does not
>acccept any parameters, thus connecting only as root.
The B in your code uses an X to connect, not A. Perhaps you're eliding too
much information.
>All the keen methods belong to the latter class, and
>since I want to connect via CGI and display the
>information they provide to the masses via their
>browser, without them entering passwords, I need to
>know how to use A's ability to connect with B's great
>methods. I've heard of something called overloading,
>but can this apply to constructors?
There's no function overloading in the C++ sense (not without using some
modules I'm not prepared to get into). There is operator overloading, but
a constructor is not an operator.
>Or do I need a
>whole new class, copying and pasting the stuff I need,
>cmopletely undermining the OO philosophy? I know
>better than to mess with the "black box".
Sometimes the black box needs messing with. Without seeing more code it's
hard to tell, but perhaps you could get what you want without modifying
existing modules by subclassing B and overriding its constructor. Cut and
paste the existing constructor and modify it to pass parameters.
>Here are the
>classes:
>
>A
>sub new {
> my $proto=shift;
> my $specs=shift;
> my $class=ref($proto) || $proto;
> my $self={};
> $self->{connection}= X::connect($specs);
> return undef unless defined $self->{$connection};
> bless ($self,$class);
> return $self;
>
>B
>sub new {
> my $proto=shift;
> my $specs=shift;
> my $class=ref($proto) || $proto;
> my $self={};
> $self->{X} = X->new();
> $self->{connection}= $self->{X}->{connection};
> return undef unless defined $self->{$connection};
> bless ($self,$class);
> return $self;
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]