in reply to Can a class constructor create an instance of a derived class and return it? Or, can objects transmute into other objects?

Why have the package SNMPDevice be a class at all?

package SNMPDevice; use strict; use SNMPDevice::CiscoWLC; use SNMPDevice::Juniper; use SNMPDevice::Generic; sub new { my( $class, %args ) = @_; my $instance_class; if( $args{ cisco } ) { $instance_class = 'SNMPDevice::CiscoWLC'; } elsif( $args{ juniper }) { $instance_class = 'SNMPDevice::Juniper'; } else { $instance_class = 'SNMPDevice::Generic'; }; return $instance_class->new( %args ); } 1;
  • Comment on Re: Can a class constructor create an instance of a derived class and return it? Or, can objects transmute into other objects?
  • Download Code

Replies are listed 'Best First'.
Re^2: Can a class constructor create an instance of a derived class and return it? Or, can objects transmute into other objects?
by poodad (Initiate) on Sep 28, 2017 at 16:19 UTC
    Because it holds some global class data.

      Why not turn this "global class data" into simply global variables?

      What makes that "global class data" different from global variables in that package?