in reply to OOP and derived classes

I think you should post some example code, maybe taken from the PODs.

Since you are using Java terminology, I'm not really sure what you mean.

Probably you are asking about perlobj#SUPER ?

edit

There is a variety of alternative "modern" OO models available, starting from "Mo" till "Moose", unfortunately I'm too confused to suggest which one to chose.

But they are heavily documented and "tutorialed"! =)

update

hmm coming from Java you will most probably like Moose, see perl moose tutorial

Cheers Rolf

PS: Je suis Charlie!

Replies are listed 'Best First'.
Re^2: OOP and derived classes
by Anonymous Monk on Feb 14, 2015 at 16:39 UTC
    for example although XML::Twig inherits from XML::Parser it explicitly instantiates a Parser object inside its constructor, but it looks in Perl that is explicit and optional. I m confused about if I can use a base class instance in place of a derived instance polymorphic wise? Are base and child classes connected polymorphicaly?
      I think you are referring to these lines from XML::Twig (taken from here)

      sub new { my ($class, %args) = @_; my $handlers; # change all nice_perlish_names into nicePerlishNames %args= _normalize_args( %args); # check options unless( $args{MoreOptions}) { foreach my $arg (keys %args) { carp "invalid option $arg" unless $valid_option{$arg}; } } # a twig is really an XML::Parser # my $self= XML::Parser->new(%args); my $self; $self= XML::Parser->new(%args); bless $self, $class; #... yadda yadda

      and indeed it does inherit from XML::Parser @ISA = qw(XML::Parser);

      This seems to be a highly complex module also playing with UNIVERSAL so I don't feel competent to comment.

      I'd say the new() method is inherited but overridden, and instead of using SUPER::new() an explicit XML::Parser->new() is used to initialize a parent object and alter it.

      TIMTOWTDI !

      Never used SUPER or Java so take it with a grain of salt, others with more expertise will comment soon on the basis of this post.

      update

      I hope it's obvious that analyzing XML::Twig is not the best way to start learning Perl's OOP. :)

      Cheers Rolf

      PS: Je suis Charlie!

        but do the other more simple modules follow this model of instantiating the base class, inside their constructor? Is it ok if I don't learn classic Perl OOP and just straight into Moose? What is the disadvantage of that?