1OBJECTS(1)            User Contributed Perl Documentation           OBJECTS(1)
2
3
4

NAME

6       PDL::Objects -- Object-Orientation, what is it and how to exploit it
7

DESCRIPTION

9       This still needs to be written properly.
10
11       Inheritance
12
13       There are basically two reasons for subclassing piddles.  The first is
14       simply that you want to be able to use your own routines like
15
16               $piddle->something()
17
18       but don't want to mess up the PDL namespace (a worthy goal, indeed!).
19       The other is that you wish to provide special handling of some func‐
20       tions or more information about the data the piddle contains.  In the
21       first case, you can do with
22
23               package BAR;
24               @ISA=qw/PDL/;
25               sub foo {my($this) = @_; fiddle;}
26
27               package main;
28               $a = PDL::pdl(BAR,5);
29               $a->foo();
30
31       However, because a PDL object is an opaque reference to a C struct, it
32       is not possible to extend the PDL class by e.g. extra data via sub‐
33       classing.  To circumvent this problem PerlDL has built-in support to
34       extent the PDL class via the has-a relation for blessed hashes.  You
35       can get the HAS-A behave like IS-A simply in that you assign the "PDL"
36       object to the attribute named PDL and redefine the method initialize().
37
38           package FOO;
39
40           @FOO::ISA = qw(PDL);
41           sub initialize {
42               my $class = shift;
43               my $self = {
44                       creation_time => time(),  # necessary extension :-)
45                       PDL => null,             # used to store PDL object
46                       };
47               bless $self, $class;
48           }
49
50       All PDL constructors will call initialize() to make sure that your
51       extentions are added by all PDL constructors automaticly.   The "PDL"
52       attribute is used by perlDL to store the PDL object and all PDL methods
53       use this attribute automaticly if they are called with a blessed hash
54       reference instead of a PDL object (a blessed scalar).
55
56       Do remember that if you subclass a class that is subclassed from a pid‐
57       dle, you need to call SUPER::initialize.
58
59       NEED STUFF ABOUT CODE REFs!!
60
61       Examples
62
63       You can find some simple examples of PDL subclassing in the PDL distri‐
64       bution test-case files. Look in "t/subclass2.t", "t/subclass3.t", etc.
65
66       Output Auto-Creation and Subclassed Objects
67
68       For PDL Functions where the output is created and returned, PDL will
69       either call the subclassed object's "initialize" or "copy" method to
70       create the output object. (See PDL::Indexing for a discussion on Output
71       Auto-Creation.) This behavior is summarized as follows:
72
73       ·
74        For Simple functions, defined as having a signature of
75
76         func( a(), [o]b() )
77
78        PDL will call $a->copy to create the output object.
79
80        In the spirit of the perl philosophy of making Easy Things Easy, This
81        behavior enables PDL-subclassed objects to be written without having
82        to overload the many simple PDL functions in this category.
83
84        The file t/subclass4.t in the PDL Distribution tests for this behav‐
85        ior.  See that file for an example.
86
87       ·
88        For other functions, PDL will call $class->initialize to create the
89        output object.  Where $class is the class name of the first argument
90        supplied to the function.
91
92        For these more complex cases, it is difficult to second-guess the sub‐
93        classed-object's designer to know if a "copy" or a "initialize" is
94        appropriate. So for these cases, $class->initialize is called by
95        default. If this is not appropriate for you, overload the function in
96        your subclass and do whatever is appropriate is the overloaded func‐
97        tion's code.
98

AUTHOR

100       Copyright (C) Karl Glazebrook (kgb@aaoepp.aao.gov.au), Tuomas J. Lukka,
101       (lukka@husc.harvard.edu) and Christian Soeller (c.soeller@auck‐
102       land.ac.nz) 2000.  Commercial reproduction of this documentation in a
103       different format is forbidden.
104
105
106
107perl v5.8.8                       2003-05-21                        OBJECTS(1)
Impressum