/[cvs]/nfo/perl/libs/DesignPattern/Bridge.pm
ViewVC logotype

Diff of /nfo/perl/libs/DesignPattern/Bridge.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by joko, Thu Feb 20 20:50:32 2003 UTC revision 1.13 by joko, Tue Jul 1 23:26:37 2003 UTC
# Line 2  Line 2 
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
13    ##  + additional checks
14    ##  + raising exceptions
15    ##
16  ##  Revision 1.10  2003/02/20 20:50:32  joko  ##  Revision 1.10  2003/02/20 20:50:32  joko
17  ##  + small exception handling: now inheriting from little Exception object  ##  + small exception handling: now inheriting from little Exception object
18  ##  ##
# Line 48  use base qw( Line 59  use base qw(
59    DesignPattern::Exception    DesignPattern::Exception
60  );  );
61    
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  # TODO / REFACTORING PROPOSAL    http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&q=mix-in+inheritance
130  # leading from Data::Storage to code abstracted out into this module - DesignPattern::Bridge    http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&q=Moo86+mixins
131  #   - this is no inheritance and it doesn't have to be    
132  #   - implement this module as a bridge to its sub-modules  
133  #   - use the BridgePattern (http://c2.com/cgi/wiki?BridgePattern)  =head3 Discussion
134  #       Using patterns was already successfully done with Data::Storage::Handler  
135  #       by implementing the AdapterPattern (http://c2.com/cgi/wiki?AdapterPattern)    http://citeseer.nj.nec.com/context/6117/0
136  #       with Perl's AUTOLOAD-mechanism  
137  #   - try to use Perl's "tie" command to implement this functionality here instead of using AUTOLOAD!  =head2 References
 #   - sub getChildNodes  
 #   - sub run  
138    
139  # 2003-02-11, joko: does this have anything in parallel with CPAN's Class::Inner?    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      via: http://citeseer.nj.nec.com/context/22076/0
164    
165      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
# Line 72  my $logger = eval { Log::Dispatch::Confi Line 249  my $logger = eval { Log::Dispatch::Confi
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;
# Line 86  sub new { Line 267  sub new {
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  }  }
# Line 227  sub new { Line 411  sub new {
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      }      }
# Line 279  sub new { Line 465  sub new {
465      my $self = shift;      my $self = shift;
466      my $includefile = shift;      my $includefile = shift;
467      my $package = shift;      my $package = shift;
468      # TODO: do better error-detection here / prevent dies under all circumstances!      
469      require $includefile;      # pre-flight checks
470        if (!$includefile) {
471          $self->raiseException('Filename for inclusion was empty.');
472          return;
473        }
474        
475        # go for it ...
476        eval("require '$includefile';");
477        # ... and handle errors afterwards catching every message from perl itself ...
478        return if $self->checkExceptions();
479        
480        # ... otherwise continue assuming everything is fine
481      $self->mixinPackage($package) if $package;      $self->mixinPackage($package) if $package;
482        
483    }    }
484    
485  1;  1;

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.13

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed