#source:http://www.perl.com/pub/a/2003/08/15/design3.html
START ===== D:\etl\Perl\DesignPatterns\RunFactoryDesignPattern.cmd
perl -w "D:\etl\Perl\DesignPatterns\RunFactoryDesignPattern.pl"
pause
END ================== D:\etl\Perl\DesignPatterns\RunFactoryDesignPattern.cmd
.
START ===== D:\etl\Perl\DesignPatterns\RunFactoryDesignPattern.pl
use strict; use warnings;
use GreetFactory;
my $greeter_n = GreetFactory->instantiate("Repeat", "I am repeating Hello x amount of times \n", 3);
$greeter_n->greet();
my $greeter_stamp = GreetFactory->instantiate("Stamp", "The Stamp says Good-bye\n");
$greeter_stamp->greet();
END ================== D:\etl\Perl\DesignPatterns\RunFactoryDesignPattern.pl
.
START ===== D:\etl\Perl\DesignPatterns\GreetFactory.pm
package GreetFactory;
use strict; use warnings;
# ARHH NO TIME HARDCODING ...
BEGIN{ push @INC, 'D:/etl/Perl/DesignPatterns'; }
sub instantiate {
my $class = shift;
my $requested_type = shift;
my $location = "Greet/$requested_type.pm";
my $class = "Greet::$requested_type";
require $location;
return $class->new(@_);
}
1;
END ================== D:\etl\Perl\DesignPatterns\GreetFactory.pm
.
START ===== D:\etl\Perl\DesignPatterns\Greet\Repeat.pm
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;
END ================== D:\etl\Perl\DesignPatterns\Greet\Repeat.pm
.
START ===== D:\etl\Perl\DesignPatterns\Greet\Stamp.pm
package Greet::Stamp;
use strict; use warnings;
sub new {
my $class = shift;
my $greeting = shift;
return bless \$greeting, $class;
}
sub greet {
my $greeting = shift;
my $stamp = timestamp();
print "$stamp $$greeting";
}
sub timestamp {
#
# Purpose: returns the time in yyyymmdd-format
#
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
#---- change 'month'- and 'year'-values to correct format ----
$min = "0$min" if ($min < 10);
$hour = "0$hour" if ($hour < 10);
$mon = $mon + 1;
$mon = "0$mon" if ($mon < 10);
$year = $year + 1900;
$mday = "0$mday" if ($mday < 10);
return "$year$mon$mday" . "_" . "$hour$min" . "_" . $sec;
}
1;
END ================== D:\etl\Perl\DesignPatterns\Greet\Stamp.pm
Getting the Current TabItem when the Tab is not selected in WPF
-
[image: Banner]
This is a quick reminder to self on how to retrieve a TabItem from a WPF
TabControl *when the tab is not currently selected* because I ru...
2 weeks ago
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!