2 |
## $Id$ |
## $Id$ |
3 |
## -------------------------------------------------------------------------------- |
## -------------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.12 2003/05/13 08:39:22 joko |
6 |
|
## autocalling constructor after instantiation |
7 |
|
## added pod documentation |
8 |
|
## |
9 |
|
## Revision 1.11 2003/02/21 08:38:21 joko |
10 |
|
## + additional checks |
11 |
|
## + raising exceptions |
12 |
|
## |
13 |
|
## Revision 1.10 2003/02/20 20:50:32 joko |
14 |
|
## + small exception handling: now inheriting from little Exception object |
15 |
|
## |
16 |
|
## Revision 1.9 2003/02/18 18:35:30 joko |
17 |
|
## + encapsulated/abstracted some more functionality: sub load_single |
18 |
|
## |
19 |
## Revision 1.8 2003/02/14 14:20:05 joko |
## Revision 1.8 2003/02/14 14:20:05 joko |
20 |
## + modified mixin behaviour |
## + modified mixin behaviour |
21 |
## |
## |
51 |
use strict; |
use strict; |
52 |
use warnings; |
use warnings; |
53 |
|
|
54 |
use base qw( DesignPattern::Object ); |
use base qw( |
55 |
|
DesignPattern::Object |
56 |
|
DesignPattern::Exception |
57 |
|
); |
58 |
|
|
59 |
|
|
60 |
use Data::Dumper; |
use Data::Dumper; |
61 |
|
|
62 |
## ======== object inheritance ======== |
=pod |
63 |
|
|
64 |
|
=head1 NAME |
65 |
|
|
66 |
|
DesignPattern::Bridge |
67 |
|
|
68 |
|
|
69 |
|
=head1 DESCRIPTION |
70 |
|
|
71 |
|
This acts as a generic backplane for plugins using "Mix-in inheritance". |
72 |
|
|
73 |
|
|
74 |
|
=head2 BACKGROUND |
75 |
|
|
76 |
|
Mix-in inheritance |
77 |
|
Please visit [http://citeseer.nj.nec.com/bracha90mixinbased.html]. |
78 |
|
|
79 |
|
[...] |
80 |
|
Abstract: The diverse inheritance mechanisms provided by Smalltalk, Beta, |
81 |
|
and CLOS are interpreted as different uses of a single underlying construct. |
82 |
|
Smalltalk and Beta differ primarily in the direction of class hierarchy growth. |
83 |
|
These inheritance mechanisms are subsumed in a new inheritance model |
84 |
|
based on composition of mixins, or abstract subclasses. This form of |
85 |
|
inheritance can also encode a CLOS multiple-inheritance hierarchy, although |
86 |
|
changes to the encoded hierarchy that would violate... (Update) |
87 |
|
[...] |
88 |
|
|
89 |
|
...level, and can naturally span component boundaries. Jiazzi supports |
90 |
|
the composition of class extending components; e.g. mixins [1]. Mixins |
91 |
|
and cyclic component linking can be combined into an open class pattern, |
92 |
|
which allows independent features that cross cut class... |
93 |
|
|
94 |
|
=head3 History of "mixins" |
95 |
|
|
96 |
|
=head4 G. Bracha, W. Cook. Mixin-based inheritance. |
97 |
|
|
98 |
|
G. Bracha and W. Cook, "Mixin-Based Inheritance", ECOOP/OOPSLA 1990, 303-311. |
99 |
|
G. Bracha, W. Cook. Mixin-based inheritance. In OOPSLA/ECOOP '90 Conference Proceedings. ACM SIGPLAN Notices 25, 10 (Oct. 1990). |
100 |
|
|
101 |
|
@inproceedings{ bracha90mixinbased, |
102 |
|
author = "Gilad Bracha and William Cook", |
103 |
|
title = "Mixin-Based Inheritance", |
104 |
|
booktitle = "Proceedings of the Conference on Object-Oriented Programming: Systems, Languages, and Applications / Proceedings of the European Conference on Object-Oriented Programming", |
105 |
|
publisher = "ACM Press", |
106 |
|
address = "Ottawa, Canada", |
107 |
|
editor = "Norman Meyrowitz", |
108 |
|
pages = "303--311", |
109 |
|
year = "1990", |
110 |
|
url = "citeseer.nj.nec.com/bracha90mixinbased.html" } |
111 |
|
|
112 |
|
=head4 D. Duggan and C. Sourelis. Mixin modules. |
113 |
|
|
114 |
|
http://users.hol.gr/~csourelis/thesis.html |
115 |
|
|
116 |
|
@misc{ duggan96mixin, |
117 |
|
author = "D. Duggan and C. Sourelis", |
118 |
|
title = "Mixin modules", |
119 |
|
text = "D. Duggan and C. Sourelis. Mixin modules. In Intl. Conf. on Functional |
120 |
|
Programming, Philadelphia, May 1996. ACM Press.", |
121 |
|
year = "1996", |
122 |
|
url = "citeseer.nj.nec.com/sourelis95mixin.html" } |
123 |
|
|
124 |
|
=head4 Google on your own: |
125 |
|
|
126 |
|
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&q=mix-in+inheritance |
127 |
|
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&q=Moo86+mixins |
128 |
|
|
129 |
|
|
130 |
|
=head3 Discussion |
131 |
|
|
132 |
|
http://citeseer.nj.nec.com/context/6117/0 |
133 |
|
|
134 |
|
=head2 References |
135 |
|
|
136 |
|
The Jigsaw Framework: |
137 |
|
http://citeseer.nj.nec.com/bracha92programming.html |
138 |
|
|
139 |
|
http://citeseer.nj.nec.com/114070.html |
140 |
|
http://citeseer.nj.nec.com/445396.html |
141 |
|
http://citeseer.nj.nec.com/tichelaar97coordination.html |
142 |
|
http://citeseer.nj.nec.com/meijler98beyond.html |
143 |
|
|
144 |
|
http://citeseer.nj.nec.com/89291.html |
145 |
|
http://citeseer.nj.nec.com/sousa91runtime.html |
146 |
|
http://citeseer.nj.nec.com/banavar95application.html |
147 |
|
http://citeseer.nj.nec.com/sourelis95mixin.html |
148 |
|
http://citeseer.nj.nec.com/hirschowitz02mixin.html |
149 |
|
|
150 |
|
Java: http://csis.pace.edu/~bergin/patterns/multipleinheritance.html |
151 |
|
C++: http://www.oofile.com.au/oofdoc/samples/ooftst19.htm |
152 |
|
|
153 |
|
=head3 Related |
154 |
|
|
155 |
|
http://citeseer.nj.nec.com/nrelated/6117/23339 |
156 |
|
|
157 |
|
|
158 |
|
=head3 Traits - Composable Units of Behavior |
159 |
|
|
160 |
|
via: http://citeseer.nj.nec.com/context/22076/0 |
161 |
|
|
162 |
|
Traits: Composable Units of Behavior - Nathanael Schrli Stphane (Correct) |
163 |
|
....is not expressive enough to factor out common features (i.e. instance |
164 |
|
variables and methods) shared by classes in a complex hierarchy. As a |
165 |
|
consequence, language designers have proposed various forms of multiple |
166 |
|
inheritance [Mey88] Kee89] Str86] as well as other mechanisms, such as |
167 |
|
mixins [Moo86] BC90] FKF98] that allow classes to be composed incrementally |
168 |
|
from sets of features. Despite the passage of nearly twenty years, neither |
169 |
|
multiple inheritance nor mixins have achieved wide acceptance [Tai96] |
170 |
|
Summarizing Alan Snyder s contribution to the inheritance panel discussion |
171 |
|
at OOPSLA .... |
172 |
|
|
173 |
|
....complete. But as a unit of reuse, a class should be small. These properties |
174 |
|
often conflict. Furthermore, the role of classes as instance generators requires |
175 |
|
that each class have a unique place in the class hierarchy, whereas units of |
176 |
|
reuse should be applicable at arbitrary places. Moon s Flavors [Moo86] were |
177 |
|
an early attempt to address this problem: Flavors are small, not necessarily |
178 |
|
complete, and they can be mixed in at arbitrary places in the class hierarchy. |
179 |
|
More sophisticated notions of mixins were subsequently developed by Bracha |
180 |
|
and Cook [BC90] and Flatt, Krishnamurthi and Felleisen .... |
181 |
|
|
182 |
|
David A. Moon. Object-oriented programming with flavors. In Proceedings |
183 |
|
OOPSLA '86, ACM SIGPLAN Notices, pages 1--8, November 1986. |
184 |
|
Published as Proceedings OOPSLA '86, ACM SIGPLAN Notices, volume 21, number 11. |
185 |
|
|
186 |
|
|
187 |
|
from: http://citeseer.nj.nec.com/566972.html |
188 |
|
|
189 |
|
Abstract: Inheritance is the fundamental reuse mechanism in object-oriented |
190 |
|
programming languages; its most prominent variants are single inheritance, |
191 |
|
multiple inheritance, and mixin inheritance. In the first part of this paper, |
192 |
|
we identify and illustrate the conceptual and practical reusability problems |
193 |
|
that arise with these forms of inheritance. We then present a simple |
194 |
|
compositional model for structuring object-oriented programs, which we call traits. |
195 |
|
Traits are essentially groups of methods... (Update) |
196 |
|
|
197 |
|
|
198 |
|
=head3 Hybrid - A Language for Programming with Active Objects |
199 |
|
|
200 |
# TODO / REFACTORING PROPOSAL |
http://citeseer.nj.nec.com/561934.html |
201 |
# leading from Data::Storage to code abstracted out into this module - DesignPattern::Bridge |
http://citeseer.nj.nec.com/nierstrasz92tour.html |
202 |
# - this is no inheritance and it doesn't have to be |
http://www.iam.unibe.ch/~scg/Archive/NFS/cao.html |
|
# - 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 |
|
203 |
|
|
204 |
# 2003-02-11, joko: does this have anything in parallel with CPAN's Class::Inner? |
=head3 Active Objects and Oberon |
205 |
|
|
206 |
|
|
207 |
|
=head2 DETAILS |
208 |
|
|
209 |
|
This attempts to be a runtime wrapper around mixin.pm, written by Michael G Schwern |
210 |
|
and available on CPAN. |
211 |
|
Please visit: |
212 |
|
http://magnonel.guild.net/~schwern/talks/Design_Patterns/full_slides/slide036.html |
213 |
|
|
214 |
|
|
215 |
|
=head2 NOTES |
216 |
|
|
217 |
|
## ======== object inheritance ======== |
218 |
|
|
219 |
|
2002-12: |
220 |
|
TODO / REFACTORING PROPOSAL |
221 |
|
leading from Data::Storage to code abstracted out into this module - DesignPattern::Bridge |
222 |
|
- this is no inheritance and it doesn't have to be |
223 |
|
- implement this module as a bridge to its sub-modules |
224 |
|
- use the BridgePattern (http://c2.com/cgi/wiki?BridgePattern) |
225 |
|
Using patterns was already successfully done with Data::Storage::Handler |
226 |
|
by implementing the AdapterPattern (http://c2.com/cgi/wiki?AdapterPattern) |
227 |
|
with Perl's AUTOLOAD-mechanism |
228 |
|
- try to use Perl's "tie" command to implement this functionality here instead of using AUTOLOAD! |
229 |
|
- sub getChildNodes |
230 |
|
- sub run |
231 |
|
|
232 |
|
2003-02-11, joko: Does this have anything in parallel with CPAN's Class::Inner? No! |
233 |
|
|
234 |
|
|
235 |
|
=head1 TODO |
236 |
|
|
237 |
|
o use Class::Loader |
238 |
|
o rename to mixin::runtime? |
239 |
|
|
240 |
|
|
241 |
|
=cut |
242 |
|
|
243 |
|
|
244 |
# get logger instance |
# get logger instance |
260 |
|
|
261 |
# create instance |
# create instance |
262 |
bless $self, $class; |
bless $self, $class; |
263 |
|
|
264 |
|
# NEW: 2003-04-16 |
265 |
|
$self->constructor() if $self->can('constructor'); |
266 |
|
|
267 |
return $self; |
return $self; |
268 |
} |
} |
315 |
sub load { |
sub load { |
316 |
|
|
317 |
my $self = shift; |
my $self = shift; |
318 |
|
my $modulename = shift; |
319 |
|
my $options = shift; |
320 |
|
|
321 |
|
if (ref $modulename eq 'ARRAY') { |
322 |
|
foreach (@$modulename) { |
323 |
|
$self->load_single($_, $options); |
324 |
|
} |
325 |
|
} else { |
326 |
|
$self->load_single($modulename, $options); |
327 |
|
} |
328 |
|
|
329 |
|
} |
330 |
|
|
331 |
|
sub load_single { |
332 |
|
|
333 |
|
my $self = shift; |
334 |
my $modulename_load = shift; |
my $modulename_load = shift; |
335 |
|
|
336 |
my $options = shift; |
my $options = shift; |
348 |
|
|
349 |
# this is the module testing phase - use mixin doesn't seem to propagate errors by default |
# this is the module testing phase - use mixin doesn't seem to propagate errors by default |
350 |
eval("use $package;"); |
eval("use $package;"); |
351 |
|
$self->checkExceptions(); |
352 |
|
|
353 |
|
=pod |
354 |
if ($@) { |
if ($@) { |
355 |
$meta->{loaded}->{$package} = 0; |
$meta->{loaded}->{$package} = 0; |
356 |
# include caller information |
# include caller information |
363 |
print $msg, "\n"; |
print $msg, "\n"; |
364 |
} |
} |
365 |
} |
} |
366 |
|
=cut |
367 |
|
|
368 |
#print "ref-1: ", ref $self, "\n"; |
#print "ref-1: ", ref $self, "\n"; |
369 |
#print "ref-2: ", ref $self::SUPER, "\n"; |
#print "ref-2: ", ref $self::SUPER, "\n"; |
456 |
my $self = shift; |
my $self = shift; |
457 |
my $includefile = shift; |
my $includefile = shift; |
458 |
my $package = shift; |
my $package = shift; |
459 |
# TODO: do better error-detection here / prevent dies under all circumstances! |
|
460 |
require $includefile; |
# pre-flight checks |
461 |
|
if (!$includefile) { |
462 |
|
$self->raiseException('Filename for inclusion was empty.'); |
463 |
|
return; |
464 |
|
} |
465 |
|
|
466 |
|
# go for it ... |
467 |
|
eval("require '$includefile';"); |
468 |
|
# ... and handle errors afterwards catching every message from perl itself ... |
469 |
|
return if $self->checkExceptions(); |
470 |
|
|
471 |
|
# ... otherwise continue assuming everything is fine |
472 |
$self->mixinPackage($package) if $package; |
$self->mixinPackage($package) if $package; |
473 |
|
|
474 |
} |
} |
475 |
|
|
476 |
1; |
1; |