Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Abstract Factory

by Khatri (Scribe)
on Oct 03, 2005 at 22:49 UTC ( [id://497072]=note: print w/replies, xml ) Need Help??


in reply to Re: Abstract Factory
in thread Abstract Factory

I've already seen it http://www.perl.com/pub/a/1999/09/refererents.html

Replies are listed 'Best First'.
Re^3: Abstract Factory
by skx (Parson) on Oct 04, 2005 at 10:53 UTC

    What part don't you understand?

    Steve
    --
      package Greet::Repeat; sub new { my $class = shift; my $self = { greeting => shift, repeat => shift, }; return bless $self, $class; } sub greet { my $self = shift; print ($self->{greeting} x $self->{repeat}); } 1;
      doesn't understand the role of shift and bless, completely; where we have greeting and repeat are being shift.
        I had same problem, Read : bless and shift
        package Bug; sub print_me { my ($self) = shift; # The @_ array now stores the arguments passed to &Bug::print_me # The rest of &print_me uses the data referred to by $self # and the explicit arguments (still in @_) } or, better still: package Bug; sub print_me { my ($self, @args) = @_; # The @args array now stores the arguments passed to &Bug::print_m +e # The rest of &print_me uses the data referred to by $self # and the explicit arguments (now in @args) }
        $nextbug = { id => "00001", type => "fatal", descr => "application does not compile", }; To turn that anonymous hash into an object of class Bug you write: bless $nextbug, "Bug";
      #!/bin/perl package first; use strict; use warnings; sub new{ my $class = shift; my $type = shift; return bless \$type, $class; } sub greet { my $type = shift; print "\n hello got something .. $$type \n"; } 1; package AFactory; use strict; use warnings; sub get_new { my $class = shift; my $type = shift; return $class->new(@_); } 1; my $greeter = AFactory->get_new("first","dow dow"); $greeter->greet(); print "hellow\n";
      !!!error is : Can't locate object method "new" via package "AFactory" at new.pl line 31.

        Can't locate object method "new" via package "AFactory" at new.pl line 31.

        That's because package "AFactory" hasn't got any method called "new". See?

        Did you think it should get it from a parent class, the one called "first" maybe?
        Then you need to specify that using either use base 'first'; or push @ISA, 'first';.

        Cheers, Sören

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://497072]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-19 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found