[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

objects

Posted on 2006-03-28
4
Medium Priority
?
207 Views
Last Modified: 2010-03-05
package test;

sub new {
  return undef if ( !defined $this->{NAME} );
}
sub createNames {
}

sub displayNames {
}

--------------------------------------------------------------------------------------------------------


package test1;

sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $this = {};
  bless($this, $class);
  my %hash = @_;

  $this->{ID}             =  $hash{ID} ;
  $this->{OBJECT}          = ### this should be object reference to package test.
  return undef if ( !defined $this->{OBJECT} );
}

sub print {

}

--------------------------------------------------------------------------------------------
package test2;
use base 'test1';
sub new {
  my $proto       = shift;
  my $class       = ref($proto) || $proto;
  my %hash      = @_;
  my $this        = {};
  bless($this, $class);
  my $this             = $class->SUPER::new(%hash_args);  
   
  return $this;
}

sub disp {
### how can i access displayNames() of class "test" here
}

--------------------------------------------------------------------------------------------


example.pl

use test2;
my $obj = test2->new(ID=>"1234");
### how can $obj access the method displ of module "test2"
### how can i call displayName of "test"
0
Comment
Question by:perlperl
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 16315963
package test1;

sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $this = {};
  bless($this, $class);
  my %hash = @_;

  $this->{ID}             =  $hash{ID} ;
  $this->{OBJECT}          = bless {},"test";
  return undef if ( !defined $this->{OBJECT} );
  return $this;
}


use test2;
my $obj = test2->new(ID=>"1234");
### how can $obj access the method displ of module "test2"
$obj->disp;
### how can i call displayName of "test"
$obj->{OBJECT}->displayNames;
0
 

Author Comment

by:perlperl
ID: 16321863
Ozo,
what will be
sub disp  { }   in package "test2"
also, will thre be any change in new() of test2
0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 16324802
sub disp {
    my $self=shift;
    print $self->{OBJECT}->displayNames();
### how can i access displayNames() of class "test" here
}
0
 

Author Comment

by:perlperl
ID: 16325001
ok..will try later and let you know....
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question