home *** CD-ROM | disk | FTP | other *** search
-
-
-
- PERLBOT(1) User Contributed Perl Documentation PERLBOT(1)
-
-
- NNNNAAAAMMMMEEEE
- perlbot - Bag'o Object Tricks (the BOT)
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- The following collection of tricks and hints is intended
- to whet curious appetites about such things as the use of
- instance variables and the mechanics of object and class
- relationships. The reader is encouraged to consult
- relevant textbooks for discussion of Object Oriented
- definitions and methodology. This is not intended as a
- tutorial for object-oriented programming or as a
- comprehensive guide to Perl's object oriented features,
- nor should it be construed as a style guide.
-
- The Perl motto still holds: There's more than one way to
- do it.
-
- OOOOOOOO SSSSCCCCAAAALLLLIIIINNNNGGGG TTTTIIIIPPPPSSSS
- 1 Do not attempt to verify the type of $$$$sssseeeellllffff. That'll
- break if the class is inherited, when the type of
- $$$$sssseeeellllffff is valid but its package isn't what you expect.
- See rule 5.
-
- 2 If an object-oriented (OO) or indirect-object (IO)
- syntax was used, then the object is probably the
- correct type and there's no need to become paranoid
- about it. Perl isn't a paranoid language anyway. If
- people subvert the OO or IO syntax then they probably
- know what they're doing and you should let them do
- it. See rule 1.
-
- 3 Use the two-argument form of _b_l_e_s_s_(_). Let a subclass
- use your constructor. See the section on _I_N_H_E_R_I_T_I_N_G
- _A _C_O_N_S_T_R_U_C_T_O_R.
-
- 4 The subclass is allowed to know things about its
- immediate superclass, the superclass is allowed to
- know nothing about a subclass.
-
- 5 Don't be trigger happy with inheritance. A "using",
- "containing", or "delegation" relationship (some sort
- of aggregation, at least) is often more appropriate.
- 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
- 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
- _D_E_L_E_G_A_T_I_O_N.
-
- 6 The object is the namespace. Make package globals
- accessible via the object. This will remove the
- guess work about the symbol's home package. See the
- 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.
-
- 7 IO syntax is certainly less noisy, but it is also
- prone to ambiguities which can cause difficult-to-
- find bugs. Allow people to use the sure-thing OO
-
-
-
- 12/Feb/96 perl 5.002 with 1
-
-
-
-
-
- PERLBOT(1) User Contributed Perl Documentation PERLBOT(1)
-
-
- syntax, even if you don't like it.
-
- 8 Do not use function-call syntax on a method. You're
- going to be bitten someday. Someone might move that
- method into a superclass and your code will be
- broken. On top of that you're feeding the paranoia
- in rule 2.
-
- 9 Don't assume you know the home package of a method.
- You're making it difficult for someone to override
- that method. See the section on _T_H_I_N_K_I_N_G _O_F _C_O_D_E
- _R_E_U_S_E.
-
- IIIINNNNSSSSTTTTAAAANNNNCCCCEEEE VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS
- An anonymous array or anonymous hash can be used to hold
- instance variables. Named parameters are also
- demonstrated.
-
- ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy %%%%ppppaaaarrrraaaammmmssss ==== @@@@____;;;;
- mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
- $$$$sssseeeellllffff---->>>>{{{{''''HHHHiiiigggghhhh''''}}}} ==== $$$$ppppaaaarrrraaaammmmssss{{{{''''HHHHiiiigggghhhh''''}}}};;;;
- $$$$sssseeeellllffff---->>>>{{{{''''LLLLoooowwww''''}}}} ==== $$$$ppppaaaarrrraaaammmmssss{{{{''''LLLLoooowwww''''}}}};;;;
- bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee BBBBaaaarrrr;;;;
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy %%%%ppppaaaarrrraaaammmmssss ==== @@@@____;;;;
- mmmmyyyy $$$$sssseeeellllffff ==== [[[[]]]];;;;
- $$$$sssseeeellllffff---->>>>[[[[0000]]]] ==== $$$$ppppaaaarrrraaaammmmssss{{{{''''LLLLeeeefffftttt''''}}}};;;;
- $$$$sssseeeellllffff---->>>>[[[[1111]]]] ==== $$$$ppppaaaarrrraaaammmmssss{{{{''''RRRRiiiigggghhhhtttt''''}}}};;;;
- bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
-
- $$$$aaaa ==== FFFFoooooooo---->>>>nnnneeeewwww(((( ''''HHHHiiiigggghhhh'''' ====>>>> 44442222,,,, ''''LLLLoooowwww'''' ====>>>> 11111111 ))));;;;
- pppprrrriiiinnnntttt """"HHHHiiiigggghhhh====$$$$aaaa---->>>>{{{{''''HHHHiiiigggghhhh''''}}}}\\\\nnnn"""";;;;
- pppprrrriiiinnnntttt """"LLLLoooowwww====$$$$aaaa---->>>>{{{{''''LLLLoooowwww''''}}}}\\\\nnnn"""";;;;
-
- $$$$bbbb ==== BBBBaaaarrrr---->>>>nnnneeeewwww(((( ''''LLLLeeeefffftttt'''' ====>>>> 77778888,,,, ''''RRRRiiiigggghhhhtttt'''' ====>>>> 44440000 ))));;;;
- pppprrrriiiinnnntttt """"LLLLeeeefffftttt====$$$$bbbb---->>>>[[[[0000]]]]\\\\nnnn"""";;;;
- pppprrrriiiinnnntttt """"RRRRiiiigggghhhhtttt====$$$$bbbb---->>>>[[[[1111]]]]\\\\nnnn"""";;;;
-
-
- SSSSCCCCAAAALLLLAAAARRRR IIIINNNNSSSSTTTTAAAANNNNCCCCEEEE VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS
- An anonymous scalar can be used when only one instance
- variable is needed.
-
-
-
- 12/Feb/96 perl 5.002 with 2
-
-
-
-
-
- PERLBOT(1) User Contributed Perl Documentation PERLBOT(1)
-
-
- ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy $$$$sssseeeellllffff;;;;
- $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
- bbbblllleeeessssssss \\\\$$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
-
- $$$$aaaa ==== FFFFoooooooo---->>>>nnnneeeewwww(((( 44442222 ))));;;;
- pppprrrriiiinnnntttt """"aaaa====$$$$$$$$aaaa\\\\nnnn"""";;;;
-
-
- IIIINNNNSSSSTTTTAAAANNNNCCCCEEEE VVVVAAAARRRRIIIIAAAABBBBLLLLEEEE IIIINNNNHHHHEEEERRRRIIIITTTTAAAANNNNCCCCEEEE
- This example demonstrates how one might inherit instance
- variables from a superclass for inclusion in the new
- class. This requires calling the superclass's constructor
- and adding one's own instance variables to the new object.
-
- ppppaaaacccckkkkaaaaggggeeee BBBBaaaarrrr;;;;
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
- $$$$sssseeeellllffff---->>>>{{{{''''bbbbuuuuzzzz''''}}}} ==== 44442222;;;;
- bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
- @@@@IIIISSSSAAAA ==== qqqqwwww(((( BBBBaaaarrrr ))));;;;
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy $$$$sssseeeellllffff ==== BBBBaaaarrrr---->>>>nnnneeeewwww;;;;
- $$$$sssseeeellllffff---->>>>{{{{''''bbbbiiiizzzz''''}}}} ==== 11111111;;;;
- bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
-
- $$$$aaaa ==== FFFFoooooooo---->>>>nnnneeeewwww;;;;
- pppprrrriiiinnnntttt """"bbbbuuuuzzzz ==== """",,,, $$$$aaaa---->>>>{{{{''''bbbbuuuuzzzz''''}}}},,,, """"\\\\nnnn"""";;;;
- pppprrrriiiinnnntttt """"bbbbiiiizzzz ==== """",,,, $$$$aaaa---->>>>{{{{''''bbbbiiiizzzz''''}}}},,,, """"\\\\nnnn"""";;;;
-
-
- OOOOBBBBJJJJEEEECCCCTTTT RRRREEEELLLLAAAATTTTIIIIOOOONNNNSSSSHHHHIIIIPPPPSSSS
- The following demonstrates how one might implement
- "containing" and "using" relationships between objects.
-
- ppppaaaacccckkkkaaaaggggeeee BBBBaaaarrrr;;;;
-
-
-
-
-
- 12/Feb/96 perl 5.002 with 3
-
-
-
-
-
- PERLBOT(1) User Contributed Perl Documentation PERLBOT(1)
-
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
- $$$$sssseeeellllffff---->>>>{{{{''''bbbbuuuuzzzz''''}}}} ==== 44442222;;;;
- bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
- $$$$sssseeeellllffff---->>>>{{{{''''BBBBaaaarrrr''''}}}} ==== BBBBaaaarrrr---->>>>nnnneeeewwww;;;;
- $$$$sssseeeellllffff---->>>>{{{{''''bbbbiiiizzzz''''}}}} ==== 11111111;;;;
- bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
-
- $$$$aaaa ==== FFFFoooooooo---->>>>nnnneeeewwww;;;;
- pppprrrriiiinnnntttt """"bbbbuuuuzzzz ==== """",,,, $$$$aaaa---->>>>{{{{''''BBBBaaaarrrr''''}}}}---->>>>{{{{''''bbbbuuuuzzzz''''}}}},,,, """"\\\\nnnn"""";;;;
- pppprrrriiiinnnntttt """"bbbbiiiizzzz ==== """",,,, $$$$aaaa---->>>>{{{{''''bbbbiiiizzzz''''}}}},,,, """"\\\\nnnn"""";;;;
-
-
- OOOOVVVVEEEERRRRRRRRIIIIDDDDIIIINNNNGGGG SSSSUUUUPPPPEEEERRRRCCCCLLLLAAAASSSSSSSS MMMMEEEETTTTHHHHOOOODDDDSSSS
- The following example demonstrates how to override a
- superclass method and then call the overridden method.
- The SSSSUUUUPPPPEEEERRRR pseudo-class allows the programmer to call an
- overridden superclass method without actually knowing
- where that method is defined.
-
- ppppaaaacccckkkkaaaaggggeeee BBBBuuuuzzzz;;;;
- ssssuuuubbbb ggggoooooooo {{{{ pppprrrriiiinnnntttt """"hhhheeeerrrreeee''''ssss tttthhhheeee ggggoooooooo\\\\nnnn"""" }}}}
-
- ppppaaaacccckkkkaaaaggggeeee BBBBaaaarrrr;;;; @@@@IIIISSSSAAAA ==== qqqqwwww(((( BBBBuuuuzzzz ))));;;;
- ssssuuuubbbb ggggoooooooogggglllleeee {{{{ pppprrrriiiinnnntttt """"ggggoooooooogggglllleeee hhhheeeerrrreeee\\\\nnnn"""" }}}}
-
- ppppaaaacccckkkkaaaaggggeeee BBBBaaaazzzz;;;;
- ssssuuuubbbb mmmmuuuummmmbbbblllleeee {{{{ pppprrrriiiinnnntttt """"mmmmuuuummmmbbbblllliiiinnnngggg\\\\nnnn"""" }}}}
-
- ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
- @@@@IIIISSSSAAAA ==== qqqqwwww(((( BBBBaaaarrrr BBBBaaaazzzz ))));;;;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 12/Feb/96 perl 5.002 with 4
-
-
-
-
-
- PERLBOT(1) User Contributed Perl Documentation PERLBOT(1)
-
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- bbbblllleeeessssssss [[[[]]]],,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
- ssssuuuubbbb ggggrrrrrrrr {{{{ pppprrrriiiinnnntttt """"ggggrrrruuuummmmbbbblllleeee\\\\nnnn"""" }}}}
- ssssuuuubbbb ggggoooooooo {{{{
- mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
- $$$$sssseeeellllffff---->>>>SSSSUUUUPPPPEEEERRRR::::::::ggggoooooooo(((())));;;;
- }}}}
- ssssuuuubbbb mmmmuuuummmmbbbblllleeee {{{{
- mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
- $$$$sssseeeellllffff---->>>>SSSSUUUUPPPPEEEERRRR::::::::mmmmuuuummmmbbbblllleeee(((())));;;;
- }}}}
- ssssuuuubbbb ggggoooooooogggglllleeee {{{{
- mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
- $$$$sssseeeellllffff---->>>>SSSSUUUUPPPPEEEERRRR::::::::ggggoooooooogggglllleeee(((())));;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
-
- $$$$ffffoooooooo ==== FFFFoooooooo---->>>>nnnneeeewwww;;;;
- $$$$ffffoooooooo---->>>>mmmmuuuummmmbbbblllleeee;;;;
- $$$$ffffoooooooo---->>>>ggggrrrrrrrr;;;;
- $$$$ffffoooooooo---->>>>ggggoooooooo;;;;
- $$$$ffffoooooooo---->>>>ggggoooooooogggglllleeee;;;;
-
-
- UUUUSSSSIIIINNNNGGGG RRRREEEELLLLAAAATTTTIIIIOOOONNNNSSSSHHHHIIIIPPPP WWWWIIIITTTTHHHH SSSSDDDDBBBBMMMM
- This example demonstrates an interface for the SDBM class.
- This creates a "using" relationship between the SDBM class
- and the new class Mydbm.
-
- ppppaaaacccckkkkaaaaggggeeee MMMMyyyyddddbbbbmmmm;;;;
-
- rrrreeeeqqqquuuuiiiirrrreeee SSSSDDDDBBBBMMMM____FFFFiiiilllleeee;;;;
- rrrreeeeqqqquuuuiiiirrrreeee TTTTiiiieeee::::::::HHHHaaaasssshhhh;;;;
- @@@@IIIISSSSAAAA ==== qqqqwwww(((( TTTTiiiieeee::::::::HHHHaaaasssshhhh ))));;;;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 12/Feb/96 perl 5.002 with 5
-
-
-
-
-
- PERLBOT(1) User Contributed Perl Documentation PERLBOT(1)
-
-
- ssssuuuubbbb TTTTIIIIEEEEHHHHAAAASSSSHHHH {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy $$$$rrrreeeeffff ==== SSSSDDDDBBBBMMMM____FFFFiiiilllleeee---->>>>nnnneeeewwww((((@@@@____))));;;;
- bbbblllleeeessssssss {{{{''''ddddbbbbmmmm'''' ====>>>> $$$$rrrreeeeffff}}}},,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
- ssssuuuubbbb FFFFEEEETTTTCCCCHHHH {{{{
- mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy $$$$rrrreeeeffff ==== $$$$sssseeeellllffff---->>>>{{{{''''ddddbbbbmmmm''''}}}};;;;
- $$$$rrrreeeeffff---->>>>FFFFEEEETTTTCCCCHHHH((((@@@@____))));;;;
- }}}}
- ssssuuuubbbb SSSSTTTTOOOORRRREEEE {{{{
- mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
- iiiiffff ((((ddddeeeeffffiiiinnnneeeedddd $$$$____[[[[0000]]]])))){{{{
- mmmmyyyy $$$$rrrreeeeffff ==== $$$$sssseeeellllffff---->>>>{{{{''''ddddbbbbmmmm''''}}}};;;;
- $$$$rrrreeeeffff---->>>>SSSSTTTTOOOORRRREEEE((((@@@@____))));;;;
- }}}} eeeellllsssseeee {{{{
- ddddiiiieeee """"CCCCaaaannnnnnnnooootttt SSSSTTTTOOOORRRREEEE aaaannnn uuuunnnnddddeeeeffffiiiinnnneeeedddd kkkkeeeeyyyy iiiinnnn MMMMyyyyddddbbbbmmmm\\\\nnnn"""";;;;
- }}}}
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
- uuuusssseeee FFFFccccnnnnttttllll qqqqwwww(((( OOOO____RRRRDDDDWWWWRRRR OOOO____CCCCRRRREEEEAAAATTTT ))));;;;
-
- ttttiiiieeee %%%%ffffoooooooo,,,, MMMMyyyyddddbbbbmmmm,,,, """"SSSSddddbbbbmmmm"""",,,, OOOO____RRRRDDDDWWWWRRRR||||OOOO____CCCCRRRREEEEAAAATTTT,,,, 0000666644440000;;;;
- $$$$ffffoooooooo{{{{''''bbbbaaaarrrr''''}}}} ==== 111122223333;;;;
- pppprrrriiiinnnntttt """"ffffoooooooo----bbbbaaaarrrr ==== $$$$ffffoooooooo{{{{''''bbbbaaaarrrr''''}}}}\\\\nnnn"""";;;;
-
- ttttiiiieeee %%%%bbbbaaaarrrr,,,, MMMMyyyyddddbbbbmmmm,,,, """"SSSSddddbbbbmmmm2222"""",,,, OOOO____RRRRDDDDWWWWRRRR||||OOOO____CCCCRRRREEEEAAAATTTT,,,, 0000666644440000;;;;
- $$$$bbbbaaaarrrr{{{{''''CCCCaaaatttthhhhyyyy''''}}}} ==== 444455556666;;;;
- pppprrrriiiinnnntttt """"bbbbaaaarrrr----CCCCaaaatttthhhhyyyy ==== $$$$bbbbaaaarrrr{{{{''''CCCCaaaatttthhhhyyyy''''}}}}\\\\nnnn"""";;;;
-
-
- TTTTHHHHIIIINNNNKKKKIIIINNNNGGGG OOOOFFFF CCCCOOOODDDDEEEE RRRREEEEUUUUSSSSEEEE
- One strength of Object-Oriented languages is the ease with
- which old code can use new code. The following examples
- will demonstrate first how one can hinder code reuse and
- then how one can promote code reuse.
-
- This first example illustrates a class which uses a fully-
- qualified method call to access the "private" method
- _B_A_Z_(_). The second example will show that it is impossible
- to override the _B_A_Z_(_) method.
-
- ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO;;;;
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- bbbblllleeeessssssss {{{{}}}},,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
- ssssuuuubbbb bbbbaaaarrrr {{{{
- mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
- $$$$sssseeeellllffff---->>>>FFFFOOOOOOOO::::::::pppprrrriiiivvvvaaaatttteeee::::::::BBBBAAAAZZZZ;;;;
- }}}}
-
-
-
-
- 12/Feb/96 perl 5.002 with 6
-
-
-
-
-
- PERLBOT(1) User Contributed Perl Documentation PERLBOT(1)
-
-
- ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO::::::::pppprrrriiiivvvvaaaatttteeee;;;;
-
- ssssuuuubbbb BBBBAAAAZZZZ {{{{
- pppprrrriiiinnnntttt """"iiiinnnn BBBBAAAAZZZZ\\\\nnnn"""";;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
-
- $$$$aaaa ==== FFFFOOOOOOOO---->>>>nnnneeeewwww;;;;
- $$$$aaaa---->>>>bbbbaaaarrrr;;;;
-
- Now we try to override the _B_A_Z_(_) method. We would like
- _F_O_O_:_:_b_a_r_(_) to call _G_O_O_P_:_:_B_A_Z_(_), but this cannot happen
- because _F_O_O_:_:_b_a_r_(_) explicitly calls _F_O_O_:_:_p_r_i_v_a_t_e_:_:_B_A_Z_(_).
-
- ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO;;;;
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- bbbblllleeeessssssss {{{{}}}},,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
- ssssuuuubbbb bbbbaaaarrrr {{{{
- mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
- $$$$sssseeeellllffff---->>>>FFFFOOOOOOOO::::::::pppprrrriiiivvvvaaaatttteeee::::::::BBBBAAAAZZZZ;;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO::::::::pppprrrriiiivvvvaaaatttteeee;;;;
-
- ssssuuuubbbb BBBBAAAAZZZZ {{{{
- pppprrrriiiinnnntttt """"iiiinnnn BBBBAAAAZZZZ\\\\nnnn"""";;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee GGGGOOOOOOOOPPPP;;;;
- @@@@IIIISSSSAAAA ==== qqqqwwww(((( FFFFOOOOOOOO ))));;;;
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- bbbblllleeeessssssss {{{{}}}},,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
-
- ssssuuuubbbb BBBBAAAAZZZZ {{{{
- pppprrrriiiinnnntttt """"iiiinnnn GGGGOOOOOOOOPPPP::::::::BBBBAAAAZZZZ\\\\nnnn"""";;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
-
- $$$$aaaa ==== GGGGOOOOOOOOPPPP---->>>>nnnneeeewwww;;;;
- $$$$aaaa---->>>>bbbbaaaarrrr;;;;
-
- To create reusable code we must modify class FOO,
- flattening class FOO::private. The next example shows a
- reusable class FOO which allows the method _G_O_O_P_:_:_B_A_Z_(_) to
- be used in place of _F_O_O_:_:_B_A_Z_(_).
-
- ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO;;;;
-
-
-
- 12/Feb/96 perl 5.002 with 7
-
-
-
-
-
- PERLBOT(1) User Contributed Perl Documentation PERLBOT(1)
-
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- bbbblllleeeessssssss {{{{}}}},,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
- ssssuuuubbbb bbbbaaaarrrr {{{{
- mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
- $$$$sssseeeellllffff---->>>>BBBBAAAAZZZZ;;;;
- }}}}
-
- ssssuuuubbbb BBBBAAAAZZZZ {{{{
- pppprrrriiiinnnntttt """"iiiinnnn BBBBAAAAZZZZ\\\\nnnn"""";;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee GGGGOOOOOOOOPPPP;;;;
- @@@@IIIISSSSAAAA ==== qqqqwwww(((( FFFFOOOOOOOO ))));;;;
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- bbbblllleeeessssssss {{{{}}}},,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
- ssssuuuubbbb BBBBAAAAZZZZ {{{{
- pppprrrriiiinnnntttt """"iiiinnnn GGGGOOOOOOOOPPPP::::::::BBBBAAAAZZZZ\\\\nnnn"""";;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
-
- $$$$aaaa ==== GGGGOOOOOOOOPPPP---->>>>nnnneeeewwww;;;;
- $$$$aaaa---->>>>bbbbaaaarrrr;;;;
-
-
- CCCCLLLLAAAASSSSSSSS CCCCOOOONNNNTTTTEEEEXXXXTTTT AAAANNNNDDDD TTTTHHHHEEEE OOOOBBBBJJJJEEEECCCCTTTT
- Use the object to solve package and class context
- problems. Everything a method needs should be available
- via the object or should be passed as a parameter to the
- method.
-
- A class will sometimes have static or global data to be
- used by the methods. A subclass may want to override that
- data and replace it with new data. When this happens the
- superclass may not know how to find the new copy of the
- data.
-
- This problem can be solved by using the object to define
- the context of the method. Let the method look in the
- object for a reference to the data. The alternative is to
- force the method to go hunting for the data ("Is it in my
- class, or in a subclass? Which subclass?"), and this can
- be inconvenient and will lead to hackery. It is better to
- just let the object tell the method where that data is
- located.
-
- ppppaaaacccckkkkaaaaggggeeee BBBBaaaarrrr;;;;
-
- %%%%ffffiiiizzzzzzzzlllleeee ==== (((( ''''PPPPaaaasssssssswwwwoooorrrrdddd'''' ====>>>> ''''XXXXYYYYZZZZZZZZYYYY'''' ))));;;;
-
-
-
- 12/Feb/96 perl 5.002 with 8
-
-
-
-
-
- PERLBOT(1) User Contributed Perl Documentation PERLBOT(1)
-
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
- $$$$sssseeeellllffff---->>>>{{{{''''ffffiiiizzzzzzzzlllleeee''''}}}} ==== \\\\%%%%ffffiiiizzzzzzzzlllleeee;;;;
- bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
-
- ssssuuuubbbb eeeennnntttteeeerrrr {{{{
- mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
-
- #### DDDDoooonnnn''''tttt ttttrrrryyyy ttttoooo gggguuuueeeessssssss iiiiffff wwwweeee sssshhhhoooouuuulllldddd uuuusssseeee %%%%BBBBaaaarrrr::::::::ffffiiiizzzzzzzzlllleeee
- #### oooorrrr %%%%FFFFoooooooo::::::::ffffiiiizzzzzzzzlllleeee.... TTTThhhheeee oooobbbbjjjjeeeecccctttt aaaallllrrrreeeeaaaaddddyyyy kkkknnnnoooowwwwssss wwwwhhhhiiiicccchhhh
- #### wwwweeee sssshhhhoooouuuulllldddd uuuusssseeee,,,, ssssoooo jjjjuuuusssstttt aaaasssskkkk iiiitttt....
- ####
- mmmmyyyy $$$$ffffiiiizzzzzzzzlllleeee ==== $$$$sssseeeellllffff---->>>>{{{{''''ffffiiiizzzzzzzzlllleeee''''}}}};;;;
-
- pppprrrriiiinnnntttt """"TTTThhhheeee wwwwoooorrrrdddd iiiissss """",,,, $$$$ffffiiiizzzzzzzzlllleeee---->>>>{{{{''''PPPPaaaasssssssswwwwoooorrrrdddd''''}}}},,,, """"\\\\nnnn"""";;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee FFFFoooooooo;;;;
- @@@@IIIISSSSAAAA ==== qqqqwwww(((( BBBBaaaarrrr ))));;;;
-
- %%%%ffffiiiizzzzzzzzlllleeee ==== (((( ''''PPPPaaaasssssssswwwwoooorrrrdddd'''' ====>>>> ''''RRRRuuuummmmpppplllleeee'''' ))));;;;
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy $$$$sssseeeellllffff ==== BBBBaaaarrrr---->>>>nnnneeeewwww;;;;
- $$$$sssseeeellllffff---->>>>{{{{''''ffffiiiizzzzzzzzlllleeee''''}}}} ==== \\\\%%%%ffffiiiizzzzzzzzlllleeee;;;;
- bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
-
- $$$$aaaa ==== BBBBaaaarrrr---->>>>nnnneeeewwww;;;;
- $$$$bbbb ==== FFFFoooooooo---->>>>nnnneeeewwww;;;;
- $$$$aaaa---->>>>eeeennnntttteeeerrrr;;;;
- $$$$bbbb---->>>>eeeennnntttteeeerrrr;;;;
-
-
- IIIINNNNHHHHEEEERRRRIIIITTTTIIIINNNNGGGG AAAA CCCCOOOONNNNSSSSTTTTRRRRUUUUCCCCTTTTOOOORRRR
- An inheritable constructor should use the second form of
- _b_l_e_s_s_(_) which allows blessing directly into a specified
- class. Notice in this example that the object will be a
- BAR not a FOO, even though the constructor is in class
- FOO.
-
- ppppaaaacccckkkkaaaaggggeeee FFFFOOOOOOOO;;;;
-
- ssssuuuubbbb nnnneeeewwww {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy $$$$sssseeeellllffff ==== {{{{}}}};;;;
- bbbblllleeeessssssss $$$$sssseeeellllffff,,,, $$$$ttttyyyyppppeeee;;;;
- }}}}
-
-
-
-
- 12/Feb/96 perl 5.002 with 9
-
-
-
-
-
- PERLBOT(1) User Contributed Perl Documentation PERLBOT(1)
-
-
- ssssuuuubbbb bbbbaaaazzzz {{{{
- pppprrrriiiinnnntttt """"iiiinnnn FFFFOOOOOOOO::::::::bbbbaaaazzzz(((())))\\\\nnnn"""";;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee BBBBAAAARRRR;;;;
- @@@@IIIISSSSAAAA ==== qqqqwwww((((FFFFOOOOOOOO))));;;;
-
- ssssuuuubbbb bbbbaaaazzzz {{{{
- pppprrrriiiinnnntttt """"iiiinnnn BBBBAAAARRRR::::::::bbbbaaaazzzz(((())))\\\\nnnn"""";;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
-
- $$$$aaaa ==== BBBBAAAARRRR---->>>>nnnneeeewwww;;;;
- $$$$aaaa---->>>>bbbbaaaazzzz;;;;
-
-
- DDDDEEEELLLLEEEEGGGGAAAATTTTIIIIOOOONNNN
- Some classes, such as SDBM_File, cannot be effectively
- subclassed because they create foreign objects. Such a
- class can be extended with some sort of aggregation
- technique such as the "using" relationship mentioned
- earlier or by delegation.
-
- The following example demonstrates delegation using an
- _A_U_T_O_L_O_A_D_(_) function to perform message-forwarding. This
- will allow the Mydbm object to behave exactly like an
- SDBM_File object. The Mydbm class could now extend the
- behavior by adding custom _F_E_T_C_H_(_) and _S_T_O_R_E_(_) methods, if
- this is desired.
-
- ppppaaaacccckkkkaaaaggggeeee MMMMyyyyddddbbbbmmmm;;;;
-
- rrrreeeeqqqquuuuiiiirrrreeee SSSSDDDDBBBBMMMM____FFFFiiiilllleeee;;;;
- rrrreeeeqqqquuuuiiiirrrreeee TTTTiiiieeee::::::::HHHHaaaasssshhhh;;;;
- @@@@IIIISSSSAAAA ==== qqqqwwww((((TTTTiiiieeee::::::::HHHHaaaasssshhhh))));;;;
-
- ssssuuuubbbb TTTTIIIIEEEEHHHHAAAASSSSHHHH {{{{
- mmmmyyyy $$$$ttttyyyyppppeeee ==== sssshhhhiiiifffftttt;;;;
- mmmmyyyy $$$$rrrreeeeffff ==== SSSSDDDDBBBBMMMM____FFFFiiiilllleeee---->>>>nnnneeeewwww((((@@@@____))));;;;
- bbbblllleeeessssssss {{{{''''ddddeeeelllleeeeggggaaaatttteeee'''' ====>>>> $$$$rrrreeeeffff}}}};;;;
- }}}}
-
- ssssuuuubbbb AAAAUUUUTTTTOOOOLLLLOOOOAAAADDDD {{{{
- mmmmyyyy $$$$sssseeeellllffff ==== sssshhhhiiiifffftttt;;;;
-
- #### TTTThhhheeee PPPPeeeerrrrllll iiiinnnntttteeeerrrrpppprrrreeeetttteeeerrrr ppppllllaaaacccceeeessss tttthhhheeee nnnnaaaammmmeeee ooooffff tttthhhheeee
- #### mmmmeeeessssssssaaaaggggeeee iiiinnnn aaaa vvvvaaaarrrriiiiaaaabbbblllleeee ccccaaaalllllllleeeedddd $$$$AAAAUUUUTTTTOOOOLLLLOOOOAAAADDDD....
-
- #### DDDDEEEESSSSTTTTRRRROOOOYYYY mmmmeeeessssssssaaaaggggeeeessss sssshhhhoooouuuulllldddd nnnneeeevvvveeeerrrr bbbbeeee pppprrrrooooppppaaaaggggaaaatttteeeedddd....
- rrrreeeettttuuuurrrrnnnn iiiiffff $$$$AAAAUUUUTTTTOOOOLLLLOOOOAAAADDDD ====~~~~ ////::::::::DDDDEEEESSSSTTTTRRRROOOOYYYY$$$$////;;;;
-
- #### RRRReeeemmmmoooovvvveeee tttthhhheeee ppppaaaacccckkkkaaaaggggeeee nnnnaaaammmmeeee....
- $$$$AAAAUUUUTTTTOOOOLLLLOOOOAAAADDDD ====~~~~ ssss////^^^^MMMMyyyyddddbbbbmmmm::::::::////////;;;;
-
-
-
- 12/Feb/96 perl 5.002 with 10
-
-
-
-
-
- PERLBOT(1) User Contributed Perl Documentation PERLBOT(1)
-
-
- #### PPPPaaaassssssss tttthhhheeee mmmmeeeessssssssaaaaggggeeee ttttoooo tttthhhheeee ddddeeeelllleeeeggggaaaatttteeee....
- $$$$sssseeeellllffff---->>>>{{{{''''ddddeeeelllleeeeggggaaaatttteeee''''}}}}---->>>>$$$$AAAAUUUUTTTTOOOOLLLLOOOOAAAADDDD((((@@@@____))));;;;
- }}}}
-
- ppppaaaacccckkkkaaaaggggeeee mmmmaaaaiiiinnnn;;;;
- uuuusssseeee FFFFccccnnnnttttllll qqqqwwww(((( OOOO____RRRRDDDDWWWWRRRR OOOO____CCCCRRRREEEEAAAATTTT ))));;;;
-
- ttttiiiieeee %%%%ffffoooooooo,,,, MMMMyyyyddddbbbbmmmm,,,, """"aaaaddddbbbbmmmm"""",,,, OOOO____RRRRDDDDWWWWRRRR||||OOOO____CCCCRRRREEEEAAAATTTT,,,, 0000666644440000;;;;
- $$$$ffffoooooooo{{{{''''bbbbaaaarrrr''''}}}} ==== 111122223333;;;;
- pppprrrriiiinnnntttt """"ffffoooooooo----bbbbaaaarrrr ==== $$$$ffffoooooooo{{{{''''bbbbaaaarrrr''''}}}}\\\\nnnn"""";;;;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 12/Feb/96 perl 5.002 with 11
-
-
-