forked from oxnz/design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
oxnz
committed
Feb 12, 2014
1 parent
46a8e6b
commit cdc3632
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package AbstractClass; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
sub new { | ||
my ($class, $args) = @_; | ||
return bless {}, $class; | ||
} | ||
|
||
sub templateMethod { | ||
my $self = shift; | ||
$self->primitiveOperation1; | ||
$self->primitiveOperation2; | ||
} | ||
|
||
sub primitiveOperation1 { | ||
die "ABSTRACT CLASS METHOD CANNOT BE CALLED DIRECTLY\n"; | ||
} | ||
|
||
sub primitiveOperation2 { | ||
die "ABSTRACT CLASS METHOD CANNOT BE CALLED DIRECTLY\n"; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package AbstractClass::ConcreteClass; | ||
use parent AbstractClass; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
sub new { | ||
my ($class, $args) = @_; | ||
my $self = {}; | ||
return bless $self, $class; | ||
} | ||
|
||
sub primitiveOperation1 { | ||
print "-->", (caller(0))[3], "\n"; | ||
} | ||
|
||
sub primitiveOperation2 { | ||
print "-->", (caller(0))[3], "\n"; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env perl | ||
# auther: oxnz | ||
# coding: utf-8 | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use AbstractClass::ConcreteClass; | ||
|
||
my $cls = AbstractClass::ConcreteClass->new; | ||
$cls->templateMethod; |