亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch14.htm

?? prrl 5 programs codes in the book
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
the program's output. This technique avoids having to call the

<TT>bless()</TT> fuNCtion in the base

class constructor.

<P>

By now, you must be wondering where polymorphism fits into this

example. Well, the simple fact that both the <TT>Pen</TT>

and <TT>Inventory_item</TT> classes

have the <TT>qtyChange()</TT> method

means that polymorphism is being used. While the <TT>Inventory_item::qtyChange()</TT>

method defaults to changing the quantity by one, the <TT>Pen::qtyChange()</TT>

method defaults to changing the quantity by 100. Because the <TT>Pen::qtyChange()</TT>

method simply modifies the behavior of <TT>Inventory_item::qtyChange()</TT>,

it does not need to know any details about how the quantity is

actually changed. This capability to change fuNCtionality without

knowing the details is a sign that abstraction is taking place.

<BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Tip</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

The <TT>Inventory_item::qtychange()</TT> notation refers to the <TT>qtyChange()</TT> fuNCtion in the <TT>Inventory_item</TT> class, and <TT>Pen::qtyChange()</TT> refers to the <TT>qtyChange()</TT> fuNCtion in the <TT>Pen</TT> class. This notation lets you 
uniquely identify any method in your script.

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<H3><A NAME="ExampleHowOneClassCanContainAnother">

Example: How One Class Can Contain Another</A></H3>

<P>

Now that you have seen several objects in action, you probably

realize that some class properties will be objects themselves.

For example, you might have a billing object that contains an

inventory object, or you might use a car object inside a warehouse

object. The possibilities are endless.

<P>

Listing 14.5 shows how to add a color object to the inventory

system you've been building. It also shows you that Perl will

execute statements that are not part of a fuNCtion-even those

in packages other than main-as soon as they are seen by the interpreter.

<P>

<IMG SRC="pseudo.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/pseudo.gif" BORDER=1 ALIGN=RIGHT><p>

<BLOCKQUOTE>

<I>Start a definition of the </I><TT><I>Inventory_item</I></TT><I>

class.<BR>

Define the constructor for the class.<BR>

Get the name of the class from the parameter array.<BR>

Assign the rest of the parameters to the </I><TT><I>%params</I></TT><I>

hash.<BR>

Bless the anonymous hash with the class name.<BR>

Use </I><TT><I>%params</I></TT><I>

to initialize the class properties.<BR>

Start a definition of the </I><TT><I>Pen</I></TT><I>

class.<BR>

Initialize the </I><TT><I>@ISA</I></TT><I>

array to define the parent classes.<BR>

Define the constructor for the class.<BR>

Get the name of the class from the parameter array.<BR>

Assign the rest of the parameters to the </I><TT><I>%params</I></TT><I>

hash.<BR>

Call the constructor for the parent class and assign the resulting

object refereNCe to </I><TT><I>$self</I></TT><I>.

<BR>

Create an entry in the anonymous hash for the </I><TT><I>INK_COLOR</I></TT><I>

key by calling the constructor for the </I><TT><I>Color</I></TT><I>

class.<BR>

Return a refereNCe to the anonymous hash that has been blessed

into the </I><TT><I>Pen</I></TT><I>

class.<BR>

Start a definition of the </I><TT><I>Color</I></TT><I>

class.<BR>

Print a message on </I><TT><I>STDOUT</I></TT><I>.

<BR>

Create two entries in the </I><TT><I>%Colors</I></TT><I>

hash.<BR>

Define the constructor for the class.<BR>

Get the name of the class from the parameter array.<BR>

Assign the rest of the parameters to the </I><TT><I>%params</I></TT><I>

hash.<BR>

Assign a refereNCe to one of the entries in the </I><TT><I>%Colors</I></TT><I>

hash to </I><TT><I>$self</I></TT><I>.

This will be used as the object refereNCe.<BR>

Bless the hash entry into the </I><TT><I>Color</I></TT><I>

class and return </I><TT><I>$self</I></TT><I>

as the object refereNCe.<BR>

Start the </I><TT><I>main</I></TT><I>

namespace.<BR>

Print a message on </I><TT><I>STDOUT</I></TT><I>.

<BR>

Call the constructor for the </I><TT><I>Pen</I></TT><I>

class. Assign the object refereNCe to </I><TT><I>$item</I></TT><I>.

<BR>

Use </I><TT><I>%properties</I></TT><I>

as a temporary value to simplify the derefereNCing process.<BR>

Print the three property values to verify that the property initialization

worked.</I>

</BLOCKQUOTE>

<HR>

<BLOCKQUOTE>

<B>Listing 14.5&nbsp;&nbsp;14LST05.PL-How One Class Can Use or

Contain Another Class<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

package Inventory_item;

    sub new {

        my($class)  = shift;

        my(%params) = @_;

        bless {

            &quot;PART_NUM&quot;    =&gt; $params{&quot;PART_NUM&quot;},

            &quot;QTY_ON_HAND&quot; =&gt; $params{&quot;QTY_ON_HAND&quot;}

        }, $class;

}



package Pen;

    @ISA = (Inventory_item);



    sub new {

        my($class) = shift;

        my(%params) = @_;

        my($self) = Inventory_item-&gt;new(@_);



        $self-&gt;{&quot;INK_COLOR&quot;} = Color-&gt;new($params{&quot;INK_COLOR&quot;});



        return(bless($self, $class));

    }



package Color;

    print(&quot;Executing Color statements\n&quot;);

    $colors{&quot;blue&quot;}  = &quot;Die Lot 13&quot;;

    $colors{&quot;red&quot;}   = &quot;Die Lot 5&quot;;



    sub new {

        my($class) = shift;

        my($param) = @_;

        my($self) = \$colors{$param};



        return(bless($self, $class));

    }





package main;

    print(&quot;Executing main statements\n&quot;);



    $pen = Pen-&gt;new(

        &quot;PART_NUM&quot;    =&gt; &quot;12A-34&quot;,

        &quot;QTY_ON_HAND&quot; =&gt; 34,

        &quot;INK_COLOR&quot;   =&gt; &quot;blue&quot;);



    %properties = %{$pen};

    print(&quot;The part number is &quot; . $properties{'PART_NUM'}     . &quot;\n&quot;);

    print(&quot;The quantity is &quot;    . $properties{'QTY_ON_HAND'}  . &quot;\n&quot;);

    print(&quot;The ink color is &quot;   . ${$properties{'INK_COLOR'}} . &quot;\n&quot;);

</PRE>

</BLOCKQUOTE>

<HR>

<P>

This program displays

<BLOCKQUOTE>

<PRE>

Executing Color statements

Executing main statements

The part number is 12A-34

The quantity is 34

The ink color is Die Lot 13

</PRE>

</BLOCKQUOTE>

<P>

Where to start? You already know about the <TT>Inventory_item</TT>

class and the <TT>@ISA</TT> array.

Let's look at the assignment to the <TT>INK_COLOR</TT>

entry of the <TT>Pen</TT> class. This

line, <TT>$self-&gt;{&quot;INK_COLOR&quot;}

= Color-&gt;new($params{&quot;INK_COLOR&quot;});</TT>,

is used to call the constructor for the <TT>Color</TT>

class. The expression <TT>$params{&quot;INK_COLOR&quot;}</TT>

passes the value of <TT>&quot;blue&quot;</TT>

to the <TT>Color</TT> constructor,

which returns a refereNCe to one of the colors in the <TT>%colors</TT>

associative array.

<P>

You can tell that Perl executes all statements that are not inside

fuNCtions because the <TT>print</TT>

statement in the <TT>Color</TT> package

is executed before the <TT>print</TT>

statement in the <TT>main</TT> package.

This is why you can define hash entries inside the <TT>Color</TT>

class. When variables are defined inside a package but outside

a fuNCtion, they are called <I>static</I> variables. You can access

one of the hash entries in the <TT>Color</TT>

package like this: <TT>$Color::colors{&quot;blue&quot;}</TT>.

<H2><A NAME="StaticVersusRegularMethodsandVariables"><FONT SIZE=5 COLOR=#FF0000>

Static Versus Regular Methods and Variables</FONT></A></H2>

<P>

You already learned that a static method is one that can be called

without needing an instantiated object. Actually, you can also

have static variables as you saw in the last section. Static variables

can be used to emulate <I>constants</I>, values that don't change.

Constants are very useful. For example, you can use them for tax

rates, mathematical constants, and things such as state abbreviations.

Here is an example using a small Perl script:

<BLOCKQUOTE>

<PRE>

package Math;

    $math{'PI'} = 3.1415;



package main;

    print(&quot;The value of PI is $Math::math{'PI'}.\n&quot;);

</PRE>

</BLOCKQUOTE>

<P>

This program displays

<BLOCKQUOTE>

<PRE>

The value of PI is 3.1415.

</PRE>

</BLOCKQUOTE>

<P>

You can also do this:

<BLOCKQUOTE>

<PRE>

package Math;

    $PI = 3.1415;

package main;

    print(&quot;The value of PI is $Math::PI.\n&quot;);

</PRE>

</BLOCKQUOTE>

<P>

Because you have been using a static method all along-the <TT>new()</TT>

method-I'll take this opportunity to demonstrate a regular fuNCtion.

Listing 14.6 shows how to use the <TT>UNIVERSAL</TT>

package to define a utility fuNCtion that is available to all

classes. 

<P>

<IMG SRC="pseudo.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/pseudo.gif" BORDER=1 ALIGN=RIGHT><p>

<BLOCKQUOTE>

<I>Start a definition of the </I><TT><I>UNIVERSAL</I></TT><I>

class.<BR>

Define the </I><TT><I>lookup()</I></TT><I>

method.<BR>

DerefereNCe the object refereNCe (the first element of </I><TT><I>@_</I></TT><I>)

and use the second parameter as the key into the anonymous hash.

Return the value of the hash entry.<BR>

Start a definition of the </I><TT><I>Inventory_item</I></TT><I>

class.<BR>

Define the constructor for the class.<BR>

Assign the rest of the parameters to the </I><TT><I>%params</I></TT><I>

hash.<BR>

Bless the anonymous hash with the class name.<BR>

Use </I><TT><I>%params</I></TT><I>

to initialize the class properties.<BR>

Start the </I><TT><I>main</I></TT><I>

namespace.<BR>

Call the constructor for the </I><TT><I>Inventory_item</I></TT><I>

class. Assign the object refereNCe to </I><TT><I>$item</I></TT><I>.

<BR>

Print the two property values using the </I><TT><I>lookup()</I></TT><I>

method to verify that the property initialization worked.</I>

</BLOCKQUOTE>

<HR>

<BLOCKQUOTE>

<B>Listing 14.6&nbsp;&nbsp;14LST06.PL-Using a Static Method to

Retrieve Class Properties<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

package UNIVERSAL;

    sub lookup {

        return(%{$_[0]}-&gt;{$_[1]});

    }



package Inventory_item;

    sub new {

        my($class)  = shift;

        my(%params) = @_;

        my($self)   = { };

                             

        $self-&gt;{&quot;PART_NUM&quot;}    = $params{&quot;PART_NUM&quot;};

        $self-&gt;{&quot;QTY_ON_HAND&quot;} = $params{&quot;QTY_ON_HAND&quot;};



        return(bless($self, $class));

    }



package main;



    $item = Inventory_item-&gt;new(&quot;PART_NUM&quot;=&gt;&quot;12A-34&quot;, &quot;QTY_ON_HAND&quot;=&gt;34);



    print(&quot;The part number is &quot; . $item-&gt;lookup('PART_NUM')     . &quot;\n&quot;);

    print(&quot;The quantity is &quot;    . $item-&gt;lookup('QTY_ON_HAND')  . &quot;\n&quot;);

</PRE>

</BLOCKQUOTE>

<HR>

<P>

I don't think this example needs any further explanation, so let's

use the space normally reserved to further discussion of the listing

and show you another utility fuNCtion instead. The <TT>printAll()</TT>

fuNCtion shown here displays all the properties of a class, or

you can specify one or more properties to display:

<BLOCKQUOTE>

<PRE>

sub printAll {

    my($self) = shift;

    my(@keys) = @_ ? @_ : sort(keys(%{$self}));



    print(&quot;CLASS: $self\n&quot;);

    foreach $key (@keys) {

        printf(&quot;\t%10.10s =&gt; $self-&gt;{$key}\n&quot;, $key);

    }

}

</PRE>

</BLOCKQUOTE>

<P>

If you put this fuNCtion into the <TT>UNIVERSAL</TT>

package, it will be available to an

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久综合丝袜日本网| 午夜精品久久久久久久 | 91九色最新地址| 日韩色在线观看| 亚洲蜜臀av乱码久久精品蜜桃| 日韩和的一区二区| 成人夜色视频网站在线观看| 91麻豆精品国产91久久久资源速度 | 亚洲激情图片qvod| 国产传媒欧美日韩成人| 这里只有精品免费| 亚洲制服欧美中文字幕中文字幕| 粉嫩嫩av羞羞动漫久久久| 日韩一区二区精品葵司在线 | 成人av综合一区| 精品三级av在线| 亚洲444eee在线观看| 97se亚洲国产综合自在线| 国产亚洲精品超碰| 精久久久久久久久久久| 欧美一区二区在线免费观看| 夜夜嗨av一区二区三区网页 | 成人永久aaa| 26uuu国产在线精品一区二区| 日韩电影一二三区| 欧美精品v日韩精品v韩国精品v| 亚洲激情中文1区| 91蜜桃免费观看视频| 成人欧美一区二区三区黑人麻豆| 国产福利一区二区三区视频在线| 精品国产乱码久久久久久闺蜜| 青青国产91久久久久久| 欧美一区二区三区播放老司机| 丝袜诱惑制服诱惑色一区在线观看| 色婷婷久久久综合中文字幕 | 亚洲天堂免费在线观看视频| 丁香婷婷深情五月亚洲| 国产精品毛片a∨一区二区三区| 国产成人精品午夜视频免费| 欧美极品xxx| 成人精品视频一区| 亚洲伦理在线精品| 欧美日韩精品电影| 久久99热国产| 中文字幕精品一区二区精品绿巨人 | 亚洲不卡在线观看| 欧美日本在线观看| 国产福利一区二区三区在线视频| 欧美精品一区二区在线播放| 国产一区二区三区四区五区入口| 国产日韩精品一区二区三区| heyzo一本久久综合| 一区二区三区日韩精品| 欧美日韩不卡视频| 狠狠色丁香久久婷婷综合丁香| 欧美激情在线看| 色999日韩国产欧美一区二区| 午夜久久久久久| 日韩欧美第一区| 成人av资源站| 日本强好片久久久久久aaa| 久久久91精品国产一区二区精品 | 欧美精品色一区二区三区| 免费的成人av| 自拍偷自拍亚洲精品播放| 欧美久久久久久蜜桃| 国产a精品视频| 亚洲国产日韩a在线播放| 久久麻豆一区二区| 91久久人澡人人添人人爽欧美| 日韩成人免费看| 亚洲欧美影音先锋| 这里只有精品电影| 91视频xxxx| 国产在线国偷精品免费看| 亚洲精品免费播放| 久久亚洲精品小早川怜子| 91电影在线观看| 粉嫩aⅴ一区二区三区四区五区| 五月激情丁香一区二区三区| 欧美激情一区二区三区在线| 欧美精品久久一区| 色悠悠久久综合| 国产精品资源站在线| 精品少妇一区二区三区在线视频 | 欧美日韩中文一区| 国产乱码精品一区二区三区五月婷| 1000精品久久久久久久久| 久久综合资源网| 欧美精品日日鲁夜夜添| 99精品国产一区二区三区不卡 | 亚洲成人久久影院| 中文字幕一区二区三区四区 | 欧美一级艳片视频免费观看| 91丨九色丨蝌蚪富婆spa| 国产主播一区二区| 青草av.久久免费一区| 亚洲精品美腿丝袜| 最新欧美精品一区二区三区| www日韩大片| 日韩一区二区不卡| 91精品婷婷国产综合久久| 91网上在线视频| www.亚洲免费av| 成人一区二区在线观看| 免费成人在线视频观看| 午夜国产精品影院在线观看| 亚洲综合在线视频| 亚洲视频免费观看| 亚洲欧洲99久久| 亚洲免费观看在线视频| 国产欧美一区二区三区在线看蜜臀 | 久久精品一区二区三区四区| 欧美videos大乳护士334| 91精品国产综合久久久蜜臀图片| 欧美色老头old∨ideo| 欧洲精品在线观看| 在线观看一区日韩| 欧美日韩视频在线一区二区 | 性做久久久久久| 亚洲美女精品一区| 一区二区三区不卡视频在线观看| 亚洲免费观看高清完整版在线 | 亚洲综合免费观看高清在线观看| 日韩毛片视频在线看| 亚洲人妖av一区二区| 樱桃视频在线观看一区| 一区二区三区美女| 日韩电影免费一区| 精品一区二区在线播放| 懂色av一区二区夜夜嗨| 国产在线播放一区| 久久精品av麻豆的观看方式| 美国欧美日韩国产在线播放| 美女视频一区在线观看| 国产精品18久久久| 色一区在线观看| 337p亚洲精品色噜噜| 精品国免费一区二区三区| 国产欧美一区二区精品性| 1024亚洲合集| 蜜臀av性久久久久蜜臀aⅴ| 国产精品456露脸| 一本久久a久久精品亚洲| 欧美一区二区三区在| 久久久午夜精品理论片中文字幕| 国产精品国产三级国产aⅴ原创| 一区二区三区在线影院| 日产国产欧美视频一区精品| 国产风韵犹存在线视精品| 日本高清不卡视频| 日韩免费视频一区二区| 中文字幕一区二区三区精华液 | 欧美在线不卡一区| 日韩欧美在线一区二区三区| 国产精品福利影院| 视频一区二区中文字幕| 国产精品一区二区男女羞羞无遮挡 | 成人久久久精品乱码一区二区三区 | 久久超碰97人人做人人爱| 91亚洲永久精品| 日韩欧美自拍偷拍| 亚洲精品免费在线观看| 国内外成人在线| 欧美日韩免费视频| 亚洲视频一区二区在线| 久久精品国产亚洲a| 日本高清不卡一区| 欧美国产一区二区| 日韩精品电影在线| 在线亚洲高清视频| 国产日产亚洲精品系列| 美女脱光内衣内裤视频久久网站 | 国产日韩精品视频一区| 亚洲18色成人| 在线亚洲人成电影网站色www| 国产三级久久久| 精品一区二区成人精品| 欧美男同性恋视频网站| 亚洲视频一区二区免费在线观看| 精东粉嫩av免费一区二区三区 | 色拍拍在线精品视频8848| 国产亚洲一区二区三区在线观看| 午夜国产不卡在线观看视频| 91亚洲永久精品| 国产精品福利av| av影院午夜一区| 国产精品麻豆一区二区| 国产成人av电影在线| 久久亚洲捆绑美女| 国模无码大尺度一区二区三区| 91精品欧美一区二区三区综合在| 亚洲主播在线观看| 欧美吞精做爰啪啪高潮| 亚洲欧美日韩国产综合在线| 国产精品久久三区| 亚洲一区二区三区三| 成人涩涩免费视频| 国产欧美日韩亚州综合| 国产91在线观看丝袜|