home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 1996 July / AMIGA_1996_7.BIN / ausgabe_7_96 / pd-programmierung / perl5_002bin.lha / man / catp / perlbot.0 < prev    next >
Text File  |  1996-03-02  |  44KB  |  727 lines

  1.  
  2.  
  3.  
  4. PERLBOT(1)     User Contributed Perl Documentation     PERLBOT(1)
  5.  
  6.  
  7. NNNNAAAAMMMMEEEE
  8.        perlbot - Bag'o Object Tricks (the BOT)
  9.  
  10. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  11.        The following collection of tricks and hints is intended
  12.        to whet curious appetites about such things as the use of
  13.        instance variables and the mechanics of object and class
  14.        relationships.  The reader is encouraged to consult
  15.        relevant textbooks for discussion of Object Oriented
  16.        definitions and methodology.  This is not intended as a
  17.        tutorial for object-oriented programming or as a
  18.        comprehensive guide to Perl's object oriented features,
  19.        nor should it be construed as a style guide.
  20.  
  21.        The Perl motto still holds:  There's more than one way to
  22.        do it.
  23.  
  24. OOOOOOOO SSSSCCCCAAAALLLLIIIINNNNGGGG TTTTIIIIPPPPSSSS
  25.        1    Do not attempt to verify the type of $$$$sssseeeellllffff.  That'll
  26.             break if the class is inherited, when the type of
  27.             $$$$sssseeeellllffff is valid but its package isn't what you expect.
  28.             See rule 5.
  29.  
  30.        2    If an object-oriented (OO) or indirect-object (IO)
  31.             syntax was used, then the object is probably the
  32.             correct type and there's no need to become paranoid
  33.             about it.  Perl isn't a paranoid language anyway.  If
  34.             people subvert the OO or IO syntax then they probably
  35.             know what they're doing and you should let them do
  36.             it.  See rule 1.
  37.  
  38.        3    Use the two-argument form of _b_l_e_s_s_(_).  Let a subclass
  39.             use your constructor.  See the section on _I_N_H_E_R_I_T_I_N_G
  40.             _A _C_O_N_S_T_R_U_C_T_O_R.
  41.  
  42.        4    The subclass is allowed to know things about its
  43.             immediate superclass, the superclass is allowed to
  44.             know nothing about a subclass.
  45.  
  46.        5    Don't be trigger happy with inheritance.  A "using",
  47.             "containing", or "delegation" relationship (some sort
  48.             of aggregation, at least) is often more appropriate.
  49.             See the section on _O_B_J_E_C_T _R_E_L_A_T_I_O_N_S_H_I_P_S, the section
  50.             on _U_S_I_N_G _R_E_L_A_T_I_O_N_S_H_I_P _W_I_T_H _S_D_B_M, and the section on
  51.             _D_E_L_E_G_A_T_I_O_N.
  52.  
  53.        6    The object is the namespace.  Make package globals
  54.             accessible via the object.  This will remove the
  55.             guess work about the symbol's home package.  See the
  56.             section on _C_L_A_S_S _C_O_N_T_E_X_T _A_N_D _T_H_E _O_B_J_E_C_T.
  57.  
  58.        7    IO syntax is certainly less noisy, but it is also
  59.             prone to ambiguities which can cause difficult-to-
  60.             find bugs.  Allow people to use the sure-thing OO
  61.  
  62.  
  63.  
  64. 12/Feb/96                perl 5.002 with                        1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. PERLBOT(1)     User Contributed Perl Documentation     PERLBOT(1)
  71.  
  72.  
  73.             syntax, even if you don't like it.
  74.  
  75.        8    Do not use function-call syntax on a method.  You're
  76.             going to be bitten someday.  Someone might move that
  77.             method into a superclass and your code will be
  78.             broken.  On top of that you're feeding the paranoia
  79.             in rule 2.
  80.  
  81.        9    Don't assume you know the home package of a method.
  82.             You're making it difficult for someone to override
  83.             that method.  See the section on _T_H_I_N_K_I_N_G _O_F _C_O_D_E
  84.             _R_E_U_S_E.
  85.  
  86. IIIINNNNSSSSTTTTAAAANNNNCCCCEEEE VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS
  87.        An anonymous array or anonymous hash can be used to hold
  88.        instance variables.  Named parameters are also
  89.        demonstrated.
  90.  
  91.                ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
  92.  
  93.                ssssuuuubbbb nnnneeeewwww {{{{
  94.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  95.                        mmmmyyyy %%%%ppppaaaarrrraaaammmmssss ==== @@@@____;;;;
  96.                        mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
  97.                        $$$$sssseeeellllffff---->>>>{{{{''''HHHHiiiigggghhhh''''}}}} ==== $$$$ppppaaaarrrraaaammmmssss{{{{''''HHHHiiiigggghhhh''''}}}};;;;
  98.                        $$$$sssseeeellllffff---->>>>{{{{''''LLLLoooowwww''''}}}}  ==== $$$$ppppaaaarrrraaaammmmssss{{{{''''LLLLoooowwww''''}}}};;;;
  99.                        bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
  100.                }}}}
  101.  
  102.                ppppaaaacccckkkkaaaaggggeeee BBBBaaaarrrr;;;;
  103.  
  104.                ssssuuuubbbb nnnneeeewwww {{{{
  105.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  106.                        mmmmyyyy %%%%ppppaaaarrrraaaammmmssss ==== @@@@____;;;;
  107.                        mmmmyyyy $$$$sssseeeellllffff ==== [[[[]]]];;;;
  108.                        $$$$sssseeeellllffff---->>>>[[[[0000]]]] ==== $$$$ppppaaaarrrraaaammmmssss{{{{''''LLLLeeeefffftttt''''}}}};;;;
  109.                        $$$$sssseeeellllffff---->>>>[[[[1111]]]] ==== $$$$ppppaaaarrrraaaammmmssss{{{{''''RRRRiiiigggghhhhtttt''''}}}};;;;
  110.                        bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
  111.                }}}}
  112.  
  113.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  114.  
  115.                $$$$aaaa ==== FFFFoooooooo---->>>>nnnneeeewwww(((( ''''HHHHiiiigggghhhh'''' ====>>>> 44442222,,,, ''''LLLLoooowwww'''' ====>>>> 11111111 ))));;;;
  116.                pppprrrriiiinnnntttt """"HHHHiiiigggghhhh====$$$$aaaa---->>>>{{{{''''HHHHiiiigggghhhh''''}}}}\\\\nnnn"""";;;;
  117.                pppprrrriiiinnnntttt """"LLLLoooowwww====$$$$aaaa---->>>>{{{{''''LLLLoooowwww''''}}}}\\\\nnnn"""";;;;
  118.  
  119.                $$$$bbbb ==== BBBBaaaarrrr---->>>>nnnneeeewwww(((( ''''LLLLeeeefffftttt'''' ====>>>> 77778888,,,, ''''RRRRiiiigggghhhhtttt'''' ====>>>> 44440000 ))));;;;
  120.                pppprrrriiiinnnntttt """"LLLLeeeefffftttt====$$$$bbbb---->>>>[[[[0000]]]]\\\\nnnn"""";;;;
  121.                pppprrrriiiinnnntttt """"RRRRiiiigggghhhhtttt====$$$$bbbb---->>>>[[[[1111]]]]\\\\nnnn"""";;;;
  122.  
  123.  
  124. SSSSCCCCAAAALLLLAAAARRRR IIIINNNNSSSSTTTTAAAANNNNCCCCEEEE VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS
  125.        An anonymous scalar can be used when only one instance
  126.        variable is needed.
  127.  
  128.  
  129.  
  130. 12/Feb/96                perl 5.002 with                        2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. PERLBOT(1)     User Contributed Perl Documentation     PERLBOT(1)
  137.  
  138.  
  139.                ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
  140.  
  141.                ssssuuuubbbb nnnneeeewwww {{{{
  142.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  143.                        mmmmyyyy $$$$sssseeeellllffff;;;;
  144.                        $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  145.                        bbbblllleeeessssssss \\\\$$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
  146.                }}}}
  147.  
  148.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  149.  
  150.                $$$$aaaa ==== FFFFoooooooo---->>>>nnnneeeewwww(((( 44442222 ))));;;;
  151.                pppprrrriiiinnnntttt """"aaaa====$$$$$$$$aaaa\\\\nnnn"""";;;;
  152.  
  153.  
  154. IIIINNNNSSSSTTTTAAAANNNNCCCCEEEE VVVVAAAARRRRIIIIAAAABBBBLLLLEEEE IIIINNNNHHHHEEEERRRRIIIITTTTAAAANNNNCCCCEEEE
  155.        This example demonstrates how one might inherit instance
  156.        variables from a superclass for inclusion in the new
  157.        class.  This requires calling the superclass's constructor
  158.        and adding one's own instance variables to the new object.
  159.  
  160.                ppppaaaacccckkkkaaaaggggeeee BBBBaaaarrrr;;;;
  161.  
  162.                ssssuuuubbbb nnnneeeewwww {{{{
  163.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  164.                        mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
  165.                        $$$$sssseeeellllffff---->>>>{{{{''''bbbbuuuuzzzz''''}}}} ==== 44442222;;;;
  166.                        bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
  167.                }}}}
  168.  
  169.                ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
  170.                @@@@IIIISSSSAAAA ==== qqqqwwww(((( BBBBaaaarrrr ))));;;;
  171.  
  172.                ssssuuuubbbb nnnneeeewwww {{{{
  173.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  174.                        mmmmyyyy $$$$sssseeeellllffff ==== BBBBaaaarrrr---->>>>nnnneeeewwww;;;;
  175.                        $$$$sssseeeellllffff---->>>>{{{{''''bbbbiiiizzzz''''}}}} ==== 11111111;;;;
  176.                        bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
  177.                }}}}
  178.  
  179.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  180.  
  181.                $$$$aaaa ==== FFFFoooooooo---->>>>nnnneeeewwww;;;;
  182.                pppprrrriiiinnnntttt """"bbbbuuuuzzzz ==== """",,,, $$$$aaaa---->>>>{{{{''''bbbbuuuuzzzz''''}}}},,,, """"\\\\nnnn"""";;;;
  183.                pppprrrriiiinnnntttt """"bbbbiiiizzzz ==== """",,,, $$$$aaaa---->>>>{{{{''''bbbbiiiizzzz''''}}}},,,, """"\\\\nnnn"""";;;;
  184.  
  185.  
  186. OOOOBBBBJJJJEEEECCCCTTTT RRRREEEELLLLAAAATTTTIIIIOOOONNNNSSSSHHHHIIIIPPPPSSSS
  187.        The following demonstrates how one might implement
  188.        "containing" and "using" relationships between objects.
  189.  
  190.                ppppaaaacccckkkkaaaaggggeeee BBBBaaaarrrr;;;;
  191.  
  192.  
  193.  
  194.  
  195.  
  196. 12/Feb/96                perl 5.002 with                        3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. PERLBOT(1)     User Contributed Perl Documentation     PERLBOT(1)
  203.  
  204.  
  205.                ssssuuuubbbb nnnneeeewwww {{{{
  206.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  207.                        mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
  208.                        $$$$sssseeeellllffff---->>>>{{{{''''bbbbuuuuzzzz''''}}}} ==== 44442222;;;;
  209.                        bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
  210.                }}}}
  211.  
  212.                ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
  213.  
  214.                ssssuuuubbbb nnnneeeewwww {{{{
  215.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  216.                        mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
  217.                        $$$$sssseeeellllffff---->>>>{{{{''''BBBBaaaarrrr''''}}}} ==== BBBBaaaarrrr---->>>>nnnneeeewwww;;;;
  218.                        $$$$sssseeeellllffff---->>>>{{{{''''bbbbiiiizzzz''''}}}} ==== 11111111;;;;
  219.                        bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
  220.                }}}}
  221.  
  222.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  223.  
  224.                $$$$aaaa ==== FFFFoooooooo---->>>>nnnneeeewwww;;;;
  225.                pppprrrriiiinnnntttt """"bbbbuuuuzzzz ==== """",,,, $$$$aaaa---->>>>{{{{''''BBBBaaaarrrr''''}}}}---->>>>{{{{''''bbbbuuuuzzzz''''}}}},,,, """"\\\\nnnn"""";;;;
  226.                pppprrrriiiinnnntttt """"bbbbiiiizzzz ==== """",,,, $$$$aaaa---->>>>{{{{''''bbbbiiiizzzz''''}}}},,,, """"\\\\nnnn"""";;;;
  227.  
  228.  
  229. OOOOVVVVEEEERRRRRRRRIIIIDDDDIIIINNNNGGGG SSSSUUUUPPPPEEEERRRRCCCCLLLLAAAASSSSSSSS MMMMEEEETTTTHHHHOOOODDDDSSSS
  230.        The following example demonstrates how to override a
  231.        superclass method and then call the overridden method.
  232.        The SSSSUUUUPPPPEEEERRRR pseudo-class allows the programmer to call an
  233.        overridden superclass method without actually knowing
  234.        where that method is defined.
  235.  
  236.                ppppaaaacccckkkkaaaaggggeeee BBBBuuuuzzzz;;;;
  237.                ssssuuuubbbb ggggoooooooo {{{{ pppprrrriiiinnnntttt """"hhhheeeerrrreeee''''ssss tttthhhheeee ggggoooooooo\\\\nnnn"""" }}}}
  238.  
  239.                ppppaaaacccckkkkaaaaggggeeee BBBBaaaarrrr;;;; @@@@IIIISSSSAAAA ==== qqqqwwww(((( BBBBuuuuzzzz ))));;;;
  240.                ssssuuuubbbb ggggoooooooogggglllleeee {{{{ pppprrrriiiinnnntttt """"ggggoooooooogggglllleeee hhhheeeerrrreeee\\\\nnnn"""" }}}}
  241.  
  242.                ppppaaaacccckkkkaaaaggggeeee BBBBaaaazzzz;;;;
  243.                ssssuuuubbbb mmmmuuuummmmbbbblllleeee {{{{ pppprrrriiiinnnntttt """"mmmmuuuummmmbbbblllliiiinnnngggg\\\\nnnn"""" }}}}
  244.  
  245.                ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
  246.                @@@@IIIISSSSAAAA ==== qqqqwwww(((( BBBBaaaarrrr BBBBaaaazzzz ))));;;;
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262. 12/Feb/96                perl 5.002 with                        4
  263.  
  264.  
  265.  
  266.  
  267.  
  268. PERLBOT(1)     User Contributed Perl Documentation     PERLBOT(1)
  269.  
  270.  
  271.                ssssuuuubbbb nnnneeeewwww {{{{
  272.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  273.                        bbbblllleeeessssssss [[[[]]]],,,, $$$$ttttyyyyppppeeee;;;;
  274.                }}}}
  275.                ssssuuuubbbb ggggrrrrrrrr {{{{ pppprrrriiiinnnntttt """"ggggrrrruuuummmmbbbblllleeee\\\\nnnn"""" }}}}
  276.                ssssuuuubbbb ggggoooooooo {{{{
  277.                        mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  278.                        $$$$sssseeeellllffff---->>>>SSSSUUUUPPPPEEEERRRR::::::::ggggoooooooo(((())));;;;
  279.                }}}}
  280.                ssssuuuubbbb mmmmuuuummmmbbbblllleeee {{{{
  281.                        mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  282.                        $$$$sssseeeellllffff---->>>>SSSSUUUUPPPPEEEERRRR::::::::mmmmuuuummmmbbbblllleeee(((())));;;;
  283.                }}}}
  284.                ssssuuuubbbb ggggoooooooogggglllleeee {{{{
  285.                        mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  286.                        $$$$sssseeeellllffff---->>>>SSSSUUUUPPPPEEEERRRR::::::::ggggoooooooogggglllleeee(((())));;;;
  287.                }}}}
  288.  
  289.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  290.  
  291.                $$$$ffffoooooooo ==== FFFFoooooooo---->>>>nnnneeeewwww;;;;
  292.                $$$$ffffoooooooo---->>>>mmmmuuuummmmbbbblllleeee;;;;
  293.                $$$$ffffoooooooo---->>>>ggggrrrrrrrr;;;;
  294.                $$$$ffffoooooooo---->>>>ggggoooooooo;;;;
  295.                $$$$ffffoooooooo---->>>>ggggoooooooogggglllleeee;;;;
  296.  
  297.  
  298. UUUUSSSSIIIINNNNGGGG RRRREEEELLLLAAAATTTTIIIIOOOONNNNSSSSHHHHIIIIPPPP WWWWIIIITTTTHHHH SSSSDDDDBBBBMMMM
  299.        This example demonstrates an interface for the SDBM class.
  300.        This creates a "using" relationship between the SDBM class
  301.        and the new class Mydbm.
  302.  
  303.                ppppaaaacccckkkkaaaaggggeeee MMMMyyyyddddbbbbmmmm;;;;
  304.  
  305.                rrrreeeeqqqquuuuiiiirrrreeee SSSSDDDDBBBBMMMM____FFFFiiiilllleeee;;;;
  306.                rrrreeeeqqqquuuuiiiirrrreeee TTTTiiiieeee::::::::HHHHaaaasssshhhh;;;;
  307.                @@@@IIIISSSSAAAA ==== qqqqwwww(((( TTTTiiiieeee::::::::HHHHaaaasssshhhh ))));;;;
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328. 12/Feb/96                perl 5.002 with                        5
  329.  
  330.  
  331.  
  332.  
  333.  
  334. PERLBOT(1)     User Contributed Perl Documentation     PERLBOT(1)
  335.  
  336.  
  337.                ssssuuuubbbb TTTTIIIIEEEEHHHHAAAASSSSHHHH {{{{
  338.                    mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  339.                    mmmmyyyy $$$$rrrreeeeffff  ==== SSSSDDDDBBBBMMMM____FFFFiiiilllleeee---->>>>nnnneeeewwww((((@@@@____))));;;;
  340.                    bbbblllleeeessssssss {{{{''''ddddbbbbmmmm'''' ====>>>> $$$$rrrreeeeffff}}}},,,, $$$$ttttyyyyppppeeee;;;;
  341.                }}}}
  342.                ssssuuuubbbb FFFFEEEETTTTCCCCHHHH {{{{
  343.                    mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  344.                    mmmmyyyy $$$$rrrreeeeffff  ==== $$$$sssseeeellllffff---->>>>{{{{''''ddddbbbbmmmm''''}}}};;;;
  345.                    $$$$rrrreeeeffff---->>>>FFFFEEEETTTTCCCCHHHH((((@@@@____))));;;;
  346.                }}}}
  347.                ssssuuuubbbb SSSSTTTTOOOORRRREEEE {{{{
  348.                    mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  349.                    iiiiffff ((((ddddeeeeffffiiiinnnneeeedddd $$$$____[[[[0000]]]])))){{{{
  350.                        mmmmyyyy $$$$rrrreeeeffff ==== $$$$sssseeeellllffff---->>>>{{{{''''ddddbbbbmmmm''''}}}};;;;
  351.                        $$$$rrrreeeeffff---->>>>SSSSTTTTOOOORRRREEEE((((@@@@____))));;;;
  352.                    }}}} eeeellllsssseeee {{{{
  353.                        ddddiiiieeee """"CCCCaaaannnnnnnnooootttt SSSSTTTTOOOORRRREEEE aaaannnn uuuunnnnddddeeeeffffiiiinnnneeeedddd kkkkeeeeyyyy iiiinnnn MMMMyyyyddddbbbbmmmm\\\\nnnn"""";;;;
  354.                    }}}}
  355.                }}}}
  356.  
  357.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  358.                uuuusssseeee FFFFccccnnnnttttllll qqqqwwww(((( OOOO____RRRRDDDDWWWWRRRR OOOO____CCCCRRRREEEEAAAATTTT ))));;;;
  359.  
  360.                ttttiiiieeee %%%%ffffoooooooo,,,, MMMMyyyyddddbbbbmmmm,,,, """"SSSSddddbbbbmmmm"""",,,, OOOO____RRRRDDDDWWWWRRRR||||OOOO____CCCCRRRREEEEAAAATTTT,,,, 0000666644440000;;;;
  361.                $$$$ffffoooooooo{{{{''''bbbbaaaarrrr''''}}}} ==== 111122223333;;;;
  362.                pppprrrriiiinnnntttt """"ffffoooooooo----bbbbaaaarrrr ==== $$$$ffffoooooooo{{{{''''bbbbaaaarrrr''''}}}}\\\\nnnn"""";;;;
  363.  
  364.                ttttiiiieeee %%%%bbbbaaaarrrr,,,, MMMMyyyyddddbbbbmmmm,,,, """"SSSSddddbbbbmmmm2222"""",,,, OOOO____RRRRDDDDWWWWRRRR||||OOOO____CCCCRRRREEEEAAAATTTT,,,, 0000666644440000;;;;
  365.                $$$$bbbbaaaarrrr{{{{''''CCCCaaaatttthhhhyyyy''''}}}} ==== 444455556666;;;;
  366.                pppprrrriiiinnnntttt """"bbbbaaaarrrr----CCCCaaaatttthhhhyyyy ==== $$$$bbbbaaaarrrr{{{{''''CCCCaaaatttthhhhyyyy''''}}}}\\\\nnnn"""";;;;
  367.  
  368.  
  369. TTTTHHHHIIIINNNNKKKKIIIINNNNGGGG OOOOFFFF CCCCOOOODDDDEEEE RRRREEEEUUUUSSSSEEEE
  370.        One strength of Object-Oriented languages is the ease with
  371.        which old code can use new code.  The following examples
  372.        will demonstrate first how one can hinder code reuse and
  373.        then how one can promote code reuse.
  374.  
  375.        This first example illustrates a class which uses a fully-
  376.        qualified method call to access the "private" method
  377.        _B_A_Z_(_).  The second example will show that it is impossible
  378.        to override the _B_A_Z_(_) method.
  379.  
  380.                ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO;;;;
  381.  
  382.                ssssuuuubbbb nnnneeeewwww {{{{
  383.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  384.                        bbbblllleeeessssssss {{{{}}}},,,, $$$$ttttyyyyppppeeee;;;;
  385.                }}}}
  386.                ssssuuuubbbb bbbbaaaarrrr {{{{
  387.                        mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  388.                        $$$$sssseeeellllffff---->>>>FFFFOOOOOOOO::::::::pppprrrriiiivvvvaaaatttteeee::::::::BBBBAAAAZZZZ;;;;
  389.                }}}}
  390.  
  391.  
  392.  
  393.  
  394. 12/Feb/96                perl 5.002 with                        6
  395.  
  396.  
  397.  
  398.  
  399.  
  400. PERLBOT(1)     User Contributed Perl Documentation     PERLBOT(1)
  401.  
  402.  
  403.                ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO::::::::pppprrrriiiivvvvaaaatttteeee;;;;
  404.  
  405.                ssssuuuubbbb BBBBAAAAZZZZ {{{{
  406.                        pppprrrriiiinnnntttt """"iiiinnnn BBBBAAAAZZZZ\\\\nnnn"""";;;;
  407.                }}}}
  408.  
  409.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  410.  
  411.                $$$$aaaa ==== FFFFOOOOOOOO---->>>>nnnneeeewwww;;;;
  412.                $$$$aaaa---->>>>bbbbaaaarrrr;;;;
  413.  
  414.        Now we try to override the _B_A_Z_(_) method.  We would like
  415.        _F_O_O_:_:_b_a_r_(_) to call _G_O_O_P_:_:_B_A_Z_(_), but this cannot happen
  416.        because _F_O_O_:_:_b_a_r_(_) explicitly calls _F_O_O_:_:_p_r_i_v_a_t_e_:_:_B_A_Z_(_).
  417.  
  418.                ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO;;;;
  419.  
  420.                ssssuuuubbbb nnnneeeewwww {{{{
  421.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  422.                        bbbblllleeeessssssss {{{{}}}},,,, $$$$ttttyyyyppppeeee;;;;
  423.                }}}}
  424.                ssssuuuubbbb bbbbaaaarrrr {{{{
  425.                        mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  426.                        $$$$sssseeeellllffff---->>>>FFFFOOOOOOOO::::::::pppprrrriiiivvvvaaaatttteeee::::::::BBBBAAAAZZZZ;;;;
  427.                }}}}
  428.  
  429.                ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO::::::::pppprrrriiiivvvvaaaatttteeee;;;;
  430.  
  431.                ssssuuuubbbb BBBBAAAAZZZZ {{{{
  432.                        pppprrrriiiinnnntttt """"iiiinnnn BBBBAAAAZZZZ\\\\nnnn"""";;;;
  433.                }}}}
  434.  
  435.                ppppaaaacccckkkkaaaaggggeeee GGGGOOOOOOOOPPPP;;;;
  436.                @@@@IIIISSSSAAAA ==== qqqqwwww(((( FFFFOOOOOOOO ))));;;;
  437.                ssssuuuubbbb nnnneeeewwww {{{{
  438.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  439.                        bbbblllleeeessssssss {{{{}}}},,,, $$$$ttttyyyyppppeeee;;;;
  440.                }}}}
  441.  
  442.                ssssuuuubbbb BBBBAAAAZZZZ {{{{
  443.                        pppprrrriiiinnnntttt """"iiiinnnn GGGGOOOOOOOOPPPP::::::::BBBBAAAAZZZZ\\\\nnnn"""";;;;
  444.                }}}}
  445.  
  446.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  447.  
  448.                $$$$aaaa ==== GGGGOOOOOOOOPPPP---->>>>nnnneeeewwww;;;;
  449.                $$$$aaaa---->>>>bbbbaaaarrrr;;;;
  450.  
  451.        To create reusable code we must modify class FOO,
  452.        flattening class FOO::private.  The next example shows a
  453.        reusable class FOO which allows the method _G_O_O_P_:_:_B_A_Z_(_) to
  454.        be used in place of _F_O_O_:_:_B_A_Z_(_).
  455.  
  456.                ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO;;;;
  457.  
  458.  
  459.  
  460. 12/Feb/96                perl 5.002 with                        7
  461.  
  462.  
  463.  
  464.  
  465.  
  466. PERLBOT(1)     User Contributed Perl Documentation     PERLBOT(1)
  467.  
  468.  
  469.                ssssuuuubbbb nnnneeeewwww {{{{
  470.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  471.                        bbbblllleeeessssssss {{{{}}}},,,, $$$$ttttyyyyppppeeee;;;;
  472.                }}}}
  473.                ssssuuuubbbb bbbbaaaarrrr {{{{
  474.                        mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  475.                        $$$$sssseeeellllffff---->>>>BBBBAAAAZZZZ;;;;
  476.                }}}}
  477.  
  478.                ssssuuuubbbb BBBBAAAAZZZZ {{{{
  479.                        pppprrrriiiinnnntttt """"iiiinnnn BBBBAAAAZZZZ\\\\nnnn"""";;;;
  480.                }}}}
  481.  
  482.                ppppaaaacccckkkkaaaaggggeeee GGGGOOOOOOOOPPPP;;;;
  483.                @@@@IIIISSSSAAAA ==== qqqqwwww(((( FFFFOOOOOOOO ))));;;;
  484.  
  485.                ssssuuuubbbb nnnneeeewwww {{{{
  486.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  487.                        bbbblllleeeessssssss {{{{}}}},,,, $$$$ttttyyyyppppeeee;;;;
  488.                }}}}
  489.                ssssuuuubbbb BBBBAAAAZZZZ {{{{
  490.                        pppprrrriiiinnnntttt """"iiiinnnn GGGGOOOOOOOOPPPP::::::::BBBBAAAAZZZZ\\\\nnnn"""";;;;
  491.                }}}}
  492.  
  493.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  494.  
  495.                $$$$aaaa ==== GGGGOOOOOOOOPPPP---->>>>nnnneeeewwww;;;;
  496.                $$$$aaaa---->>>>bbbbaaaarrrr;;;;
  497.  
  498.  
  499. CCCCLLLLAAAASSSSSSSS CCCCOOOONNNNTTTTEEEEXXXXTTTT AAAANNNNDDDD TTTTHHHHEEEE OOOOBBBBJJJJEEEECCCCTTTT
  500.        Use the object to solve package and class context
  501.        problems.  Everything a method needs should be available
  502.        via the object or should be passed as a parameter to the
  503.        method.
  504.  
  505.        A class will sometimes have static or global data to be
  506.        used by the methods.  A subclass may want to override that
  507.        data and replace it with new data.  When this happens the
  508.        superclass may not know how to find the new copy of the
  509.        data.
  510.  
  511.        This problem can be solved by using the object to define
  512.        the context of the method.  Let the method look in the
  513.        object for a reference to the data.  The alternative is to
  514.        force the method to go hunting for the data ("Is it in my
  515.        class, or in a subclass?  Which subclass?"), and this can
  516.        be inconvenient and will lead to hackery.  It is better to
  517.        just let the object tell the method where that data is
  518.        located.
  519.  
  520.                ppppaaaacccckkkkaaaaggggeeee BBBBaaaarrrr;;;;
  521.  
  522.                %%%%ffffiiiizzzzzzzzlllleeee ==== (((( ''''PPPPaaaasssssssswwwwoooorrrrdddd'''' ====>>>> ''''XXXXYYYYZZZZZZZZYYYY'''' ))));;;;
  523.  
  524.  
  525.  
  526. 12/Feb/96                perl 5.002 with                        8
  527.  
  528.  
  529.  
  530.  
  531.  
  532. PERLBOT(1)     User Contributed Perl Documentation     PERLBOT(1)
  533.  
  534.  
  535.                ssssuuuubbbb nnnneeeewwww {{{{
  536.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  537.                        mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
  538.                        $$$$sssseeeellllffff---->>>>{{{{''''ffffiiiizzzzzzzzlllleeee''''}}}} ==== \\\\%%%%ffffiiiizzzzzzzzlllleeee;;;;
  539.                        bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
  540.                }}}}
  541.  
  542.                ssssuuuubbbb eeeennnntttteeeerrrr {{{{
  543.                        mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  544.  
  545.                        #### DDDDoooonnnn''''tttt ttttrrrryyyy ttttoooo gggguuuueeeessssssss iiiiffff wwwweeee sssshhhhoooouuuulllldddd uuuusssseeee %%%%BBBBaaaarrrr::::::::ffffiiiizzzzzzzzlllleeee
  546.                        #### oooorrrr %%%%FFFFoooooooo::::::::ffffiiiizzzzzzzzlllleeee....  TTTThhhheeee oooobbbbjjjjeeeecccctttt aaaallllrrrreeeeaaaaddddyyyy kkkknnnnoooowwwwssss wwwwhhhhiiiicccchhhh
  547.                        #### wwwweeee sssshhhhoooouuuulllldddd uuuusssseeee,,,, ssssoooo jjjjuuuusssstttt aaaasssskkkk iiiitttt....
  548.                        ####
  549.                        mmmmyyyy $$$$ffffiiiizzzzzzzzlllleeee ==== $$$$sssseeeellllffff---->>>>{{{{''''ffffiiiizzzzzzzzlllleeee''''}}}};;;;
  550.  
  551.                        pppprrrriiiinnnntttt """"TTTThhhheeee wwwwoooorrrrdddd iiiissss """",,,, $$$$ffffiiiizzzzzzzzlllleeee---->>>>{{{{''''PPPPaaaasssssssswwwwoooorrrrdddd''''}}}},,,, """"\\\\nnnn"""";;;;
  552.                }}}}
  553.  
  554.                ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
  555.                @@@@IIIISSSSAAAA ==== qqqqwwww(((( BBBBaaaarrrr ))));;;;
  556.  
  557.                %%%%ffffiiiizzzzzzzzlllleeee ==== (((( ''''PPPPaaaasssssssswwwwoooorrrrdddd'''' ====>>>> ''''RRRRuuuummmmpppplllleeee'''' ))));;;;
  558.  
  559.                ssssuuuubbbb nnnneeeewwww {{{{
  560.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  561.                        mmmmyyyy $$$$sssseeeellllffff ==== BBBBaaaarrrr---->>>>nnnneeeewwww;;;;
  562.                        $$$$sssseeeellllffff---->>>>{{{{''''ffffiiiizzzzzzzzlllleeee''''}}}} ==== \\\\%%%%ffffiiiizzzzzzzzlllleeee;;;;
  563.                        bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
  564.                }}}}
  565.  
  566.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  567.  
  568.                $$$$aaaa ==== BBBBaaaarrrr---->>>>nnnneeeewwww;;;;
  569.                $$$$bbbb ==== FFFFoooooooo---->>>>nnnneeeewwww;;;;
  570.                $$$$aaaa---->>>>eeeennnntttteeeerrrr;;;;
  571.                $$$$bbbb---->>>>eeeennnntttteeeerrrr;;;;
  572.  
  573.  
  574. IIIINNNNHHHHEEEERRRRIIIITTTTIIIINNNNGGGG AAAA CCCCOOOONNNNSSSSTTTTRRRRUUUUCCCCTTTTOOOORRRR
  575.        An inheritable constructor should use the second form of
  576.        _b_l_e_s_s_(_) which allows blessing directly into a specified
  577.        class.  Notice in this example that the object will be a
  578.        BAR not a FOO, even though the constructor is in class
  579.        FOO.
  580.  
  581.                ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO;;;;
  582.  
  583.                ssssuuuubbbb nnnneeeewwww {{{{
  584.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  585.                        mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
  586.                        bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
  587.                }}}}
  588.  
  589.  
  590.  
  591.  
  592. 12/Feb/96                perl 5.002 with                        9
  593.  
  594.  
  595.  
  596.  
  597.  
  598. PERLBOT(1)     User Contributed Perl Documentation     PERLBOT(1)
  599.  
  600.  
  601.                ssssuuuubbbb bbbbaaaazzzz {{{{
  602.                        pppprrrriiiinnnntttt """"iiiinnnn FFFFOOOOOOOO::::::::bbbbaaaazzzz(((())))\\\\nnnn"""";;;;
  603.                }}}}
  604.  
  605.                ppppaaaacccckkkkaaaaggggeeee BBBBAAAARRRR;;;;
  606.                @@@@IIIISSSSAAAA ==== qqqqwwww((((FFFFOOOOOOOO))));;;;
  607.  
  608.                ssssuuuubbbb bbbbaaaazzzz {{{{
  609.                        pppprrrriiiinnnntttt """"iiiinnnn BBBBAAAARRRR::::::::bbbbaaaazzzz(((())))\\\\nnnn"""";;;;
  610.                }}}}
  611.  
  612.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  613.  
  614.                $$$$aaaa ==== BBBBAAAARRRR---->>>>nnnneeeewwww;;;;
  615.                $$$$aaaa---->>>>bbbbaaaazzzz;;;;
  616.  
  617.  
  618. DDDDEEEELLLLEEEEGGGGAAAATTTTIIIIOOOONNNN
  619.        Some classes, such as SDBM_File, cannot be effectively
  620.        subclassed because they create foreign objects.  Such a
  621.        class can be extended with some sort of aggregation
  622.        technique such as the "using" relationship mentioned
  623.        earlier or by delegation.
  624.  
  625.        The following example demonstrates delegation using an
  626.        _A_U_T_O_L_O_A_D_(_) function to perform message-forwarding.  This
  627.        will allow the Mydbm object to behave exactly like an
  628.        SDBM_File object.  The Mydbm class could now extend the
  629.        behavior by adding custom _F_E_T_C_H_(_) and _S_T_O_R_E_(_) methods, if
  630.        this is desired.
  631.  
  632.                ppppaaaacccckkkkaaaaggggeeee MMMMyyyyddddbbbbmmmm;;;;
  633.  
  634.                rrrreeeeqqqquuuuiiiirrrreeee SSSSDDDDBBBBMMMM____FFFFiiiilllleeee;;;;
  635.                rrrreeeeqqqquuuuiiiirrrreeee TTTTiiiieeee::::::::HHHHaaaasssshhhh;;;;
  636.                @@@@IIIISSSSAAAA ==== qqqqwwww((((TTTTiiiieeee::::::::HHHHaaaasssshhhh))));;;;
  637.  
  638.                ssssuuuubbbb TTTTIIIIEEEEHHHHAAAASSSSHHHH {{{{
  639.                        mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
  640.                        mmmmyyyy $$$$rrrreeeeffff ==== SSSSDDDDBBBBMMMM____FFFFiiiilllleeee---->>>>nnnneeeewwww((((@@@@____))));;;;
  641.                        bbbblllleeeessssssss {{{{''''ddddeeeelllleeeeggggaaaatttteeee'''' ====>>>> $$$$rrrreeeeffff}}}};;;;
  642.                }}}}
  643.  
  644.                ssssuuuubbbb AAAAUUUUTTTTOOOOLLLLOOOOAAAADDDD {{{{
  645.                        mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
  646.  
  647.                        #### TTTThhhheeee PPPPeeeerrrrllll iiiinnnntttteeeerrrrpppprrrreeeetttteeeerrrr ppppllllaaaacccceeeessss tttthhhheeee nnnnaaaammmmeeee ooooffff tttthhhheeee
  648.                        #### mmmmeeeessssssssaaaaggggeeee iiiinnnn aaaa vvvvaaaarrrriiiiaaaabbbblllleeee ccccaaaalllllllleeeedddd $$$$AAAAUUUUTTTTOOOOLLLLOOOOAAAADDDD....
  649.  
  650.                        #### DDDDEEEESSSSTTTTRRRROOOOYYYY mmmmeeeessssssssaaaaggggeeeessss sssshhhhoooouuuulllldddd nnnneeeevvvveeeerrrr bbbbeeee pppprrrrooooppppaaaaggggaaaatttteeeedddd....
  651.                        rrrreeeettttuuuurrrrnnnn iiiiffff $$$$AAAAUUUUTTTTOOOOLLLLOOOOAAAADDDD ====~~~~ ////::::::::DDDDEEEESSSSTTTTRRRROOOOYYYY$$$$////;;;;
  652.  
  653.                        #### RRRReeeemmmmoooovvvveeee tttthhhheeee ppppaaaacccckkkkaaaaggggeeee nnnnaaaammmmeeee....
  654.                        $$$$AAAAUUUUTTTTOOOOLLLLOOOOAAAADDDD ====~~~~ ssss////^^^^MMMMyyyyddddbbbbmmmm::::::::////////;;;;
  655.  
  656.  
  657.  
  658. 12/Feb/96                perl 5.002 with                       10
  659.  
  660.  
  661.  
  662.  
  663.  
  664. PERLBOT(1)     User Contributed Perl Documentation     PERLBOT(1)
  665.  
  666.  
  667.                        #### PPPPaaaassssssss tttthhhheeee mmmmeeeessssssssaaaaggggeeee ttttoooo tttthhhheeee ddddeeeelllleeeeggggaaaatttteeee....
  668.                        $$$$sssseeeellllffff---->>>>{{{{''''ddddeeeelllleeeeggggaaaatttteeee''''}}}}---->>>>$$$$AAAAUUUUTTTTOOOOLLLLOOOOAAAADDDD((((@@@@____))));;;;
  669.                }}}}
  670.  
  671.                ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
  672.                uuuusssseeee FFFFccccnnnnttttllll qqqqwwww(((( OOOO____RRRRDDDDWWWWRRRR OOOO____CCCCRRRREEEEAAAATTTT ))));;;;
  673.  
  674.                ttttiiiieeee %%%%ffffoooooooo,,,, MMMMyyyyddddbbbbmmmm,,,, """"aaaaddddbbbbmmmm"""",,,, OOOO____RRRRDDDDWWWWRRRR||||OOOO____CCCCRRRREEEEAAAATTTT,,,, 0000666644440000;;;;
  675.                $$$$ffffoooooooo{{{{''''bbbbaaaarrrr''''}}}} ==== 111122223333;;;;
  676.                pppprrrriiiinnnntttt """"ffffoooooooo----bbbbaaaarrrr ==== $$$$ffffoooooooo{{{{''''bbbbaaaarrrr''''}}}}\\\\nnnn"""";;;;
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724. 12/Feb/96                perl 5.002 with                       11
  725.  
  726.  
  727.