| 2 |
## $Id$ |
## $Id$ |
| 3 |
## -------------------------------------------------------------------------------- |
## -------------------------------------------------------------------------------- |
| 4 |
## $Log$ |
## $Log$ |
| 5 |
|
## Revision 1.13 2003/07/01 23:26:37 joko |
| 6 |
|
## croak to STDERR if module loading fails! |
| 7 |
|
## |
| 8 |
|
## Revision 1.12 2003/05/13 08:39:22 joko |
| 9 |
|
## autocalling constructor after instantiation |
| 10 |
|
## added pod documentation |
| 11 |
|
## |
| 12 |
## Revision 1.11 2003/02/21 08:38:21 joko |
## Revision 1.11 2003/02/21 08:38:21 joko |
| 13 |
## + additional checks |
## + additional checks |
| 14 |
## + raising exceptions |
## + raising exceptions |
| 62 |
|
|
| 63 |
use Data::Dumper; |
use Data::Dumper; |
| 64 |
|
|
| 65 |
## ======== object inheritance ======== |
=pod |
| 66 |
|
|
| 67 |
|
=head1 NAME |
| 68 |
|
|
| 69 |
|
DesignPattern::Bridge |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
=head1 DESCRIPTION |
| 73 |
|
|
| 74 |
|
This acts as a generic backplane for plugins using "Mix-in inheritance". |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
=head2 BACKGROUND |
| 78 |
|
|
| 79 |
|
Mix-in inheritance |
| 80 |
|
Please visit [http://citeseer.nj.nec.com/bracha90mixinbased.html]. |
| 81 |
|
|
| 82 |
|
[...] |
| 83 |
|
Abstract: The diverse inheritance mechanisms provided by Smalltalk, Beta, |
| 84 |
|
and CLOS are interpreted as different uses of a single underlying construct. |
| 85 |
|
Smalltalk and Beta differ primarily in the direction of class hierarchy growth. |
| 86 |
|
These inheritance mechanisms are subsumed in a new inheritance model |
| 87 |
|
based on composition of mixins, or abstract subclasses. This form of |
| 88 |
|
inheritance can also encode a CLOS multiple-inheritance hierarchy, although |
| 89 |
|
changes to the encoded hierarchy that would violate... (Update) |
| 90 |
|
[...] |
| 91 |
|
|
| 92 |
|
...level, and can naturally span component boundaries. Jiazzi supports |
| 93 |
|
the composition of class extending components; e.g. mixins [1]. Mixins |
| 94 |
|
and cyclic component linking can be combined into an open class pattern, |
| 95 |
|
which allows independent features that cross cut class... |
| 96 |
|
|
| 97 |
|
=head3 History of "mixins" |
| 98 |
|
|
| 99 |
|
=head4 G. Bracha, W. Cook. Mixin-based inheritance. |
| 100 |
|
|
| 101 |
|
G. Bracha and W. Cook, "Mixin-Based Inheritance", ECOOP/OOPSLA 1990, 303-311. |
| 102 |
|
G. Bracha, W. Cook. Mixin-based inheritance. In OOPSLA/ECOOP '90 Conference Proceedings. ACM SIGPLAN Notices 25, 10 (Oct. 1990). |
| 103 |
|
|
| 104 |
|
@inproceedings{ bracha90mixinbased, |
| 105 |
|
author = "Gilad Bracha and William Cook", |
| 106 |
|
title = "Mixin-Based Inheritance", |
| 107 |
|
booktitle = "Proceedings of the Conference on Object-Oriented Programming: Systems, Languages, and Applications / Proceedings of the European Conference on Object-Oriented Programming", |
| 108 |
|
publisher = "ACM Press", |
| 109 |
|
address = "Ottawa, Canada", |
| 110 |
|
editor = "Norman Meyrowitz", |
| 111 |
|
pages = "303--311", |
| 112 |
|
year = "1990", |
| 113 |
|
url = "citeseer.nj.nec.com/bracha90mixinbased.html" } |
| 114 |
|
|
| 115 |
|
=head4 D. Duggan and C. Sourelis. Mixin modules. |
| 116 |
|
|
| 117 |
|
http://users.hol.gr/~csourelis/thesis.html |
| 118 |
|
|
| 119 |
|
@misc{ duggan96mixin, |
| 120 |
|
author = "D. Duggan and C. Sourelis", |
| 121 |
|
title = "Mixin modules", |
| 122 |
|
text = "D. Duggan and C. Sourelis. Mixin modules. In Intl. Conf. on Functional |
| 123 |
|
Programming, Philadelphia, May 1996. ACM Press.", |
| 124 |
|
year = "1996", |
| 125 |
|
url = "citeseer.nj.nec.com/sourelis95mixin.html" } |
| 126 |
|
|
| 127 |
|
=head4 Google on your own: |
| 128 |
|
|
| 129 |
|
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&q=mix-in+inheritance |
| 130 |
|
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&q=Moo86+mixins |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
=head3 Discussion |
| 134 |
|
|
| 135 |
|
http://citeseer.nj.nec.com/context/6117/0 |
| 136 |
|
|
| 137 |
|
=head2 References |
| 138 |
|
|
| 139 |
|
The Jigsaw Framework: |
| 140 |
|
http://citeseer.nj.nec.com/bracha92programming.html |
| 141 |
|
|
| 142 |
|
http://citeseer.nj.nec.com/114070.html |
| 143 |
|
http://citeseer.nj.nec.com/445396.html |
| 144 |
|
http://citeseer.nj.nec.com/tichelaar97coordination.html |
| 145 |
|
http://citeseer.nj.nec.com/meijler98beyond.html |
| 146 |
|
|
| 147 |
|
http://citeseer.nj.nec.com/89291.html |
| 148 |
|
http://citeseer.nj.nec.com/sousa91runtime.html |
| 149 |
|
http://citeseer.nj.nec.com/banavar95application.html |
| 150 |
|
http://citeseer.nj.nec.com/sourelis95mixin.html |
| 151 |
|
http://citeseer.nj.nec.com/hirschowitz02mixin.html |
| 152 |
|
|
| 153 |
|
Java: http://csis.pace.edu/~bergin/patterns/multipleinheritance.html |
| 154 |
|
C++: http://www.oofile.com.au/oofdoc/samples/ooftst19.htm |
| 155 |
|
|
| 156 |
|
=head3 Related |
| 157 |
|
|
| 158 |
|
http://citeseer.nj.nec.com/nrelated/6117/23339 |
| 159 |
|
|
| 160 |
|
|
| 161 |
|
=head3 Traits - Composable Units of Behavior |
| 162 |
|
|
| 163 |
# TODO / REFACTORING PROPOSAL |
via: http://citeseer.nj.nec.com/context/22076/0 |
|
# leading from Data::Storage to code abstracted out into this module - DesignPattern::Bridge |
|
|
# - this is no inheritance and it doesn't have to be |
|
|
# - implement this module as a bridge to its sub-modules |
|
|
# - use the BridgePattern (http://c2.com/cgi/wiki?BridgePattern) |
|
|
# Using patterns was already successfully done with Data::Storage::Handler |
|
|
# by implementing the AdapterPattern (http://c2.com/cgi/wiki?AdapterPattern) |
|
|
# with Perl's AUTOLOAD-mechanism |
|
|
# - try to use Perl's "tie" command to implement this functionality here instead of using AUTOLOAD! |
|
|
# - sub getChildNodes |
|
|
# - sub run |
|
| 164 |
|
|
| 165 |
# 2003-02-11, joko: does this have anything in parallel with CPAN's Class::Inner? |
Traits: Composable Units of Behavior - Nathanael Schrli Stphane (Correct) |
| 166 |
|
....is not expressive enough to factor out common features (i.e. instance |
| 167 |
|
variables and methods) shared by classes in a complex hierarchy. As a |
| 168 |
|
consequence, language designers have proposed various forms of multiple |
| 169 |
|
inheritance [Mey88] Kee89] Str86] as well as other mechanisms, such as |
| 170 |
|
mixins [Moo86] BC90] FKF98] that allow classes to be composed incrementally |
| 171 |
|
from sets of features. Despite the passage of nearly twenty years, neither |
| 172 |
|
multiple inheritance nor mixins have achieved wide acceptance [Tai96] |
| 173 |
|
Summarizing Alan Snyder s contribution to the inheritance panel discussion |
| 174 |
|
at OOPSLA .... |
| 175 |
|
|
| 176 |
|
....complete. But as a unit of reuse, a class should be small. These properties |
| 177 |
|
often conflict. Furthermore, the role of classes as instance generators requires |
| 178 |
|
that each class have a unique place in the class hierarchy, whereas units of |
| 179 |
|
reuse should be applicable at arbitrary places. Moon s Flavors [Moo86] were |
| 180 |
|
an early attempt to address this problem: Flavors are small, not necessarily |
| 181 |
|
complete, and they can be mixed in at arbitrary places in the class hierarchy. |
| 182 |
|
More sophisticated notions of mixins were subsequently developed by Bracha |
| 183 |
|
and Cook [BC90] and Flatt, Krishnamurthi and Felleisen .... |
| 184 |
|
|
| 185 |
|
David A. Moon. Object-oriented programming with flavors. In Proceedings |
| 186 |
|
OOPSLA '86, ACM SIGPLAN Notices, pages 1--8, November 1986. |
| 187 |
|
Published as Proceedings OOPSLA '86, ACM SIGPLAN Notices, volume 21, number 11. |
| 188 |
|
|
| 189 |
|
|
| 190 |
|
from: http://citeseer.nj.nec.com/566972.html |
| 191 |
|
|
| 192 |
|
Abstract: Inheritance is the fundamental reuse mechanism in object-oriented |
| 193 |
|
programming languages; its most prominent variants are single inheritance, |
| 194 |
|
multiple inheritance, and mixin inheritance. In the first part of this paper, |
| 195 |
|
we identify and illustrate the conceptual and practical reusability problems |
| 196 |
|
that arise with these forms of inheritance. We then present a simple |
| 197 |
|
compositional model for structuring object-oriented programs, which we call traits. |
| 198 |
|
Traits are essentially groups of methods... (Update) |
| 199 |
|
|
| 200 |
|
|
| 201 |
|
=head3 Hybrid - A Language for Programming with Active Objects |
| 202 |
|
|
| 203 |
|
http://citeseer.nj.nec.com/561934.html |
| 204 |
|
http://citeseer.nj.nec.com/nierstrasz92tour.html |
| 205 |
|
http://www.iam.unibe.ch/~scg/Archive/NFS/cao.html |
| 206 |
|
|
| 207 |
|
=head3 Active Objects and Oberon |
| 208 |
|
|
| 209 |
|
|
| 210 |
|
=head2 DETAILS |
| 211 |
|
|
| 212 |
|
This attempts to be a runtime wrapper around mixin.pm, written by Michael G Schwern |
| 213 |
|
and available on CPAN. |
| 214 |
|
Please visit: |
| 215 |
|
http://magnonel.guild.net/~schwern/talks/Design_Patterns/full_slides/slide036.html |
| 216 |
|
|
| 217 |
|
|
| 218 |
|
=head2 NOTES |
| 219 |
|
|
| 220 |
|
## ======== object inheritance ======== |
| 221 |
|
|
| 222 |
|
2002-12: |
| 223 |
|
TODO / REFACTORING PROPOSAL |
| 224 |
|
leading from Data::Storage to code abstracted out into this module - DesignPattern::Bridge |
| 225 |
|
- this is no inheritance and it doesn't have to be |
| 226 |
|
- implement this module as a bridge to its sub-modules |
| 227 |
|
- use the BridgePattern (http://c2.com/cgi/wiki?BridgePattern) |
| 228 |
|
Using patterns was already successfully done with Data::Storage::Handler |
| 229 |
|
by implementing the AdapterPattern (http://c2.com/cgi/wiki?AdapterPattern) |
| 230 |
|
with Perl's AUTOLOAD-mechanism |
| 231 |
|
- try to use Perl's "tie" command to implement this functionality here instead of using AUTOLOAD! |
| 232 |
|
- sub getChildNodes |
| 233 |
|
- sub run |
| 234 |
|
|
| 235 |
|
2003-02-11, joko: Does this have anything in parallel with CPAN's Class::Inner? No! |
| 236 |
|
|
| 237 |
|
|
| 238 |
|
=head1 TODO |
| 239 |
|
|
| 240 |
|
o use Class::Loader |
| 241 |
|
o rename to mixin::runtime? |
| 242 |
|
|
| 243 |
|
|
| 244 |
|
=cut |
| 245 |
|
|
| 246 |
|
|
| 247 |
# get logger instance |
# get logger instance |
| 249 |
|
|
| 250 |
my $meta; |
my $meta; |
| 251 |
|
|
| 252 |
|
|
| 253 |
|
sub DEBUG { 1 } |
| 254 |
|
|
| 255 |
|
|
| 256 |
## ======== object constructor ======== |
## ======== object constructor ======== |
| 257 |
sub new { |
sub new { |
| 258 |
my $invocant = shift; |
my $invocant = shift; |
| 267 |
|
|
| 268 |
# create instance |
# create instance |
| 269 |
bless $self, $class; |
bless $self, $class; |
| 270 |
|
|
| 271 |
|
# NEW: 2003-04-16 |
| 272 |
|
$self->constructor() if $self->can('constructor'); |
| 273 |
|
|
| 274 |
return $self; |
return $self; |
| 275 |
} |
} |
| 411 |
# FIXME: --- this is redundant --- |
# FIXME: --- this is redundant --- |
| 412 |
if ($@) { |
if ($@) { |
| 413 |
$meta->{loaded}->{$package} = 0; |
$meta->{loaded}->{$package} = 0; |
| 414 |
$logger->error( __PACKAGE__ . "->load: $@" ) if $logger; |
my $msg = __PACKAGE__ . "->load: $@"; |
| 415 |
|
print STDERR $msg, "\n" if DEBUG; |
| 416 |
|
$logger->error( $msg ) if $logger; |
| 417 |
} else { |
} else { |
| 418 |
$meta->{loaded}->{$package} = 1; |
$meta->{loaded}->{$package} = 1; |
| 419 |
} |
} |