[Bioperl-l] multiple inheritance

Steve Mathias smathias at unm.edu
Wed Jul 30 16:50:20 EDT 2003


>>>>> "Jaso    n" == Jason Stajich <jason at cgt.duhs.duke.edu> writes:

Jason> Hmm - how should we solve the multiple inheritance when we want
Jason> to chain both constructors.  Using SUPER just goes up the tree
Jason> and will follow B first up to A and never call C's constructor.

Jason> package D; @ISA = qw(B C);

Jason>    A
Jason>   / \
Jason>   B C
Jason>   \ /
Jason>    D

Jason> The Right Way* to do this is of course not having multiple
Jason> inheritance OR to use The Damian's NEXT
Jason> http://search.cpan.org/author/DCONWAY/NEXT-0.50/lib/NEXT.pm

Jason> We run into this for SeqFeature::SimilarityPair which ISA
Jason> FeaturePair and a Similarity - the soln there was not to rely on
Jason> the constructor for initializing parameters.

Jason> I am hitting it again for my Tree::AlleleNode objects which are
Jason> PopGen::Individuals (genotype containers) and Tree::Node (as part
Jason> of the coalescent).

Jason> My soln will be to explictly code all the initialization
Jason> parameters for the skipped superclass (C as in above example) as
Jason> copy+paste

I like NEXT, although I don't use it much since I mostly still use
5.6.1, so I can understand why you wouldn't want to make it another
bioperl dependency.  In fact I might plead that you don't :-).  However,
instead of re-coding everything, why not at least do something along the
lines of:

package D; 
@ISA = qw(B C);
...
sub _init {
  my($self, %init) = @_;
  $self->B::_init(%init);
  $self->C::_init(%init);
  # do whetever D-specific initialization
}

Jason> NEXT is part of perl 5.8.0 and would remove a lot of issues wrt
Jason> to chaining destructors that we have some code hacks for in
Jason> Bio::Root::Root.  But I am wary of adding another module
Jason> dependancy.

Jason> Comments?

Jason> -- Jason Stajich Duke University jason at cgt.mc.duke.edu
Jason> _______________________________________________ Bioperl-l mailing
Jason> list Bioperl-l at portal.open-bio.org
Jason> http://portal.open-bio.org/mailman/listinfo/bioperl-l

-- 
(    Stephen L. Mathias, Ph.D.                     (                    (
 )   Office of Biocomputing                         )  s m a t h i a s   )
(    University of New Mexico School of Medicine   (   @ p o b l a n o  (
 )   MSC08 4560                                     )  . h e a l t h .   )
(    915 Camino de Salud, NE                       (   u n m . e d u    (
 )   Albuquerque, NM 87131-5196                     )                    )


More information about the Bioperl-l mailing list