Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Abstract Factory

by skx (Parson)
on Oct 04, 2005 at 10:53 UTC ( [id://497193]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Abstract Factory
in thread Abstract Factory

What part don't you understand?

Steve
--

Replies are listed 'Best First'.
Re^4: Abstract Factory
by Khatri (Scribe) on Oct 05, 2005 at 17:44 UTC
    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";
Re^5: Abstract Factory
by Khatri (Scribe) on Oct 05, 2005 at 21:11 UTC
    #!/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://497193]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found