At 04:39 AM 8/16/01 -0700, Blair Burns wrote:
>Thanks for your reply, Peter. I think I didn't label
>my packages clearly for you, which likely makes a big
>difference ;-) If this tidbit changes your reply, let
>me know.

Not really.  See below.

> > The B in your code uses an X to connect, not A.
> > Perhaps you're eliding too
> > much information.
>
>package X;
>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;
>
>package Y;
>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;

Okay, to satisfy your requirements below, can't you do something like

package Z;
use base Y;

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;
}

BTW, Randal calls the '$class=ref($proto) || $proto' trick "cargo cult 
programming" and allows that it is essentially pointless; I have come to 
agree with him.

>--- Peter Scott <[EMAIL PROTECTED]> wrote:
> > 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.
> >
>
>
>__________________________________________________
>Do You Yahoo!?
>Make international calls for as low as $.04/minute with Yahoo! Messenger
>http://phonecard.yahoo.com/
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to